Skip to content

Commit

Permalink
[web] Respond with null for unimplemented method channels (#21423)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdebbar authored Sep 26, 2020
1 parent df83e8f commit fc7d0fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,10 @@ class EngineWindow extends ui.Window {
return;
}

// TODO(flutter_web): Some Flutter widgets send platform messages that we
// don't handle on web. So for now, let's just ignore them. In the future,
// we should consider uncommenting the following "callback(null)" line.

// Passing [null] to [callback] indicates that the platform message isn't
// implemented. Look at [MethodChannel.invokeMethod] to see how [null] is
// handled.
// callback(null);
_replyToPlatformMessage(callback, null);
}

int _getHapticFeedbackDuration(String? type) {
Expand Down
18 changes: 18 additions & 0 deletions lib/web_ui/test/engine/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ void testMain() {
await completer.future;
});

test('sendPlatformMessage responds even when channel is unknown', () async {
bool responded = false;

final ByteData inputData = ByteData(4);
inputData.setUint32(0, 42);
window.sendPlatformMessage(
'flutter/__unknown__channel__',
null,
(outputData) {
responded = true;
expect(outputData, isNull);
},
);

await Future<void>.delayed(const Duration(milliseconds: 1));
expect(responded, isTrue);
});

test('Window implements locale, locales, and locale change notifications', () async {
// This will count how many times we notified about locale changes.
int localeChangedCount = 0;
Expand Down

0 comments on commit fc7d0fc

Please sign in to comment.