Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
03817a99
Unverified
Commit
03817a99
authored
Apr 09, 2019
by
Jonah Williams
Committed by
GitHub
Apr 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cast NPE in invokeListMethod and invokeMapMathod (#30760)
parent
b1611cc9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
2 deletions
+32
-2
platform_channel.dart
packages/flutter/lib/src/services/platform_channel.dart
+2
-2
platform_channel_test.dart
packages/flutter/test/services/platform_channel_test.dart
+30
-0
No files found.
packages/flutter/lib/src/services/platform_channel.dart
View file @
03817a99
...
@@ -314,7 +314,7 @@ class MethodChannel {
...
@@ -314,7 +314,7 @@ class MethodChannel {
/// * [invokeMethod], which this call delegates to.
/// * [invokeMethod], which this call delegates to.
Future
<
List
<
T
>>
invokeListMethod
<
T
>(
String
method
,
[
dynamic
arguments
])
async
{
Future
<
List
<
T
>>
invokeListMethod
<
T
>(
String
method
,
[
dynamic
arguments
])
async
{
final
List
<
dynamic
>
result
=
await
invokeMethod
<
List
<
dynamic
>>(
method
,
arguments
);
final
List
<
dynamic
>
result
=
await
invokeMethod
<
List
<
dynamic
>>(
method
,
arguments
);
return
result
.
cast
<
T
>();
return
result
?
.
cast
<
T
>();
}
}
/// An implementation of [invokeMethod] that can return typed maps.
/// An implementation of [invokeMethod] that can return typed maps.
...
@@ -328,7 +328,7 @@ class MethodChannel {
...
@@ -328,7 +328,7 @@ class MethodChannel {
/// * [invokeMethod], which this call delegates to.
/// * [invokeMethod], which this call delegates to.
Future
<
Map
<
K
,
V
>>
invokeMapMethod
<
K
,
V
>(
String
method
,
[
dynamic
arguments
])
async
{
Future
<
Map
<
K
,
V
>>
invokeMapMethod
<
K
,
V
>(
String
method
,
[
dynamic
arguments
])
async
{
final
Map
<
dynamic
,
dynamic
>
result
=
await
invokeMethod
<
Map
<
dynamic
,
dynamic
>>(
method
,
arguments
);
final
Map
<
dynamic
,
dynamic
>
result
=
await
invokeMethod
<
Map
<
dynamic
,
dynamic
>>(
method
,
arguments
);
return
result
.
cast
<
K
,
V
>();
return
result
?
.
cast
<
K
,
V
>();
}
}
/// Sets a callback for receiving method calls on this channel.
/// Sets a callback for receiving method calls on this channel.
...
...
packages/flutter/test/services/platform_channel_test.dart
View file @
03817a99
...
@@ -69,6 +69,21 @@ void main() {
...
@@ -69,6 +69,21 @@ void main() {
expect
(
await
channel
.
invokeListMethod
<
String
>(
'sayHello'
,
'hello'
),
<
String
>[
'hello'
,
'world'
]);
expect
(
await
channel
.
invokeListMethod
<
String
>(
'sayHello'
,
'hello'
),
<
String
>[
'hello'
,
'world'
]);
});
});
test
(
'can invoke list method and get null result'
,
()
async
{
BinaryMessages
.
setMockMessageHandler
(
'ch7'
,
(
ByteData
message
)
async
{
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
if
(
methodCall
[
'method'
]
==
'sayHello'
)
{
return
jsonMessage
.
encodeMessage
(<
dynamic
>[
null
]);
}
else
{
return
jsonMessage
.
encodeMessage
(<
dynamic
>[
'unknown'
,
null
,
null
]);
}
},
);
expect
(
await
channel
.
invokeListMethod
<
String
>(
'sayHello'
,
'hello'
),
null
);
});
test
(
'can invoke map method and get result'
,
()
async
{
test
(
'can invoke map method and get result'
,
()
async
{
BinaryMessages
.
setMockMessageHandler
(
BinaryMessages
.
setMockMessageHandler
(
...
@@ -86,6 +101,21 @@ void main() {
...
@@ -86,6 +101,21 @@ void main() {
expect
(
await
channel
.
invokeMapMethod
<
String
,
String
>(
'sayHello'
,
'hello'
),
<
String
,
String
>{
'hello'
:
'world'
});
expect
(
await
channel
.
invokeMapMethod
<
String
,
String
>(
'sayHello'
,
'hello'
),
<
String
,
String
>{
'hello'
:
'world'
});
});
});
test
(
'can invoke map method and get null result'
,
()
async
{
BinaryMessages
.
setMockMessageHandler
(
'ch7'
,
(
ByteData
message
)
async
{
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
if
(
methodCall
[
'method'
]
==
'sayHello'
)
{
return
jsonMessage
.
encodeMessage
(<
dynamic
>[
null
]);
}
else
{
return
jsonMessage
.
encodeMessage
(<
dynamic
>[
'unknown'
,
null
,
null
]);
}
},
);
expect
(
await
channel
.
invokeMapMethod
<
String
,
String
>(
'sayHello'
,
'hello'
),
null
);
});
test
(
'can invoke method and get error'
,
()
async
{
test
(
'can invoke method and get error'
,
()
async
{
BinaryMessages
.
setMockMessageHandler
(
BinaryMessages
.
setMockMessageHandler
(
'ch7'
,
'ch7'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment