Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fc7d0fc

Browse files
authored
[web] Respond with null for unimplemented method channels (#21423)
1 parent df83e8f commit fc7d0fc

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

lib/web_ui/lib/src/engine/window.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,10 @@ class EngineWindow extends ui.Window {
679679
return;
680680
}
681681

682-
// TODO(flutter_web): Some Flutter widgets send platform messages that we
683-
// don't handle on web. So for now, let's just ignore them. In the future,
684-
// we should consider uncommenting the following "callback(null)" line.
685-
686682
// Passing [null] to [callback] indicates that the platform message isn't
687683
// implemented. Look at [MethodChannel.invokeMethod] to see how [null] is
688684
// handled.
689-
// callback(null);
685+
_replyToPlatformMessage(callback, null);
690686
}
691687

692688
int _getHapticFeedbackDuration(String? type) {

lib/web_ui/test/engine/window_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ void testMain() {
229229
await completer.future;
230230
});
231231

232+
test('sendPlatformMessage responds even when channel is unknown', () async {
233+
bool responded = false;
234+
235+
final ByteData inputData = ByteData(4);
236+
inputData.setUint32(0, 42);
237+
window.sendPlatformMessage(
238+
'flutter/__unknown__channel__',
239+
null,
240+
(outputData) {
241+
responded = true;
242+
expect(outputData, isNull);
243+
},
244+
);
245+
246+
await Future<void>.delayed(const Duration(milliseconds: 1));
247+
expect(responded, isTrue);
248+
});
249+
232250
test('Window implements locale, locales, and locale change notifications', () async {
233251
// This will count how many times we notified about locale changes.
234252
int localeChangedCount = 0;

0 commit comments

Comments
 (0)