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
177e99b3
Unverified
Commit
177e99b3
authored
Nov 09, 2017
by
Mikkel Nygaard Ravn
Committed by
GitHub
Nov 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support unpacking platform error events (#12938)
parent
436aa930
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
15 deletions
+48
-15
platform_channel.dart
packages/flutter/lib/src/services/platform_channel.dart
+9
-4
platform_channel_test.dart
packages/flutter/test/services/platform_channel_test.dart
+39
-11
No files found.
packages/flutter/lib/src/services/platform_channel.dart
View file @
177e99b3
...
...
@@ -268,7 +268,7 @@ class EventChannel {
/// * a decoded data event (possibly null) for each successful event
/// received from the platform plugin;
/// * an error event containing a [PlatformException] for each error event
/// received from the platform plugin
;
/// received from the platform plugin
.
///
/// Errors occurring during stream activation or deactivation are reported
/// through the [FlutterError] facility. Stream activation happens only when
...
...
@@ -279,10 +279,15 @@ class EventChannel {
StreamController
<
dynamic
>
controller
;
controller
=
new
StreamController
<
dynamic
>.
broadcast
(
onListen:
()
async
{
BinaryMessages
.
setMessageHandler
(
name
,
(
ByteData
reply
)
async
{
if
(
reply
==
null
)
if
(
reply
==
null
)
{
controller
.
close
();
else
}
else
{
try
{
controller
.
add
(
codec
.
decodeEnvelope
(
reply
));
}
on
PlatformException
catch
(
e
)
{
controller
.
addError
(
e
);
}
}
});
try
{
await
methodChannel
.
invokeMethod
(
'listen'
,
arguments
);
...
...
packages/flutter/test/services/platform_channel_test.dart
View file @
177e99b3
...
...
@@ -161,7 +161,6 @@ void main() {
const
MessageCodec
<
dynamic
>
jsonMessage
=
const
JSONMessageCodec
();
const
MethodCodec
jsonMethod
=
const
JSONMethodCodec
();
const
EventChannel
channel
=
const
EventChannel
(
'ch'
,
jsonMethod
);
test
(
'can receive event stream'
,
()
async
{
void
emitEvent
(
dynamic
event
)
{
BinaryMessages
.
handlePlatformMessage
(
'ch'
,
...
...
@@ -169,6 +168,7 @@ void main() {
(
ByteData
reply
)
{},
);
}
test
(
'can receive event stream'
,
()
async
{
bool
canceled
=
false
;
BinaryMessages
.
setMockMessageHandler
(
'ch'
,
...
...
@@ -176,13 +176,13 @@ void main() {
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
if
(
methodCall
[
'method'
]
==
'listen'
)
{
final
String
argument
=
methodCall
[
'args'
];
emitEvent
(
jsonMe
ssage
.
encodeMessage
(<
dynamic
>[
argument
+
'1'
]
));
emitEvent
(
jsonMe
ssage
.
encodeMessage
(<
dynamic
>[
argument
+
'2'
]
));
emitEvent
(
jsonMe
thod
.
encodeSuccessEnvelope
(
argument
+
'1'
));
emitEvent
(
jsonMe
thod
.
encodeSuccessEnvelope
(
argument
+
'2'
));
emitEvent
(
null
);
return
jsonMe
ssage
.
encodeMessage
(<
dynamic
>[
null
]
);
return
jsonMe
thod
.
encodeSuccessEnvelope
(
null
);
}
else
if
(
methodCall
[
'method'
]
==
'cancel'
)
{
canceled
=
true
;
return
jsonMe
ssage
.
encodeMessage
(<
dynamic
>[
null
]
);
return
jsonMe
thod
.
encodeSuccessEnvelope
(
null
);
}
else
{
fail
(
'Expected listen or cancel'
);
}
...
...
@@ -193,5 +193,33 @@ void main() {
await
new
Future
<
Null
>.
delayed
(
Duration
.
ZERO
);
expect
(
canceled
,
isTrue
);
});
test
(
'can receive error event'
,
()
async
{
BinaryMessages
.
setMockMessageHandler
(
'ch'
,
(
ByteData
message
)
async
{
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
if
(
methodCall
[
'method'
]
==
'listen'
)
{
final
String
argument
=
methodCall
[
'args'
];
emitEvent
(
jsonMethod
.
encodeErrorEnvelope
(
code:
'404'
,
message:
'Not Found.'
,
details:
argument
));
return
jsonMethod
.
encodeSuccessEnvelope
(
null
);
}
else
if
(
methodCall
[
'method'
]
==
'cancel'
)
{
return
jsonMethod
.
encodeSuccessEnvelope
(
null
);
}
else
{
fail
(
'Expected listen or cancel'
);
}
},
);
final
List
<
dynamic
>
events
=
<
dynamic
>[];
final
List
<
dynamic
>
errors
=
<
dynamic
>[];
channel
.
receiveBroadcastStream
(
'hello'
).
listen
(
events
.
add
,
onError:
errors
.
add
);
await
new
Future
<
Null
>.
delayed
(
Duration
.
ZERO
);
expect
(
events
,
isEmpty
);
expect
(
errors
,
hasLength
(
1
));
expect
(
errors
[
0
],
const
isInstanceOf
<
PlatformException
>());
final
PlatformException
error
=
errors
[
0
];
expect
(
error
.
code
,
'404'
);
expect
(
error
.
message
,
'Not Found.'
);
expect
(
error
.
details
,
'hello'
);
});
});
}
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