Skip to content
Merged
Prev Previous commit
Next Next commit
Return '(null)' when message.body is null
  • Loading branch information
LinXunFeng committed Mar 25, 2025
commit ef6ccae30679874f210812532d5ac4d61a7bb556
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ Future<void> main() async {
await pageFinished.future;

await controller.runJavaScript('Channel.postMessage(undefined);');
await expectLater(channelCompleter.future, completion(''));
await expectLater(channelCompleter.future, completion('(null)'));
});

testWidgets('resize webview', (WidgetTester tester) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,13 @@ class WebKitJavaScriptChannelParams extends JavaScriptChannelParams {
(WeakReference<void Function(JavaScriptMessage)> weakReference) {
return (_, __, WKScriptMessage message) {
if (weakReference.target != null) {
// When message.body is null, return '(null)' for consistency
// with previous implementations.
weakReference.target!(
JavaScriptMessage(message: message.body?.toString() ?? ''),
JavaScriptMessage(
message: message.body == null
? '(null)'
: message.body!.toString()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ! shouldn't be needed here, for the same reason.

);
}
};
Expand Down