part of 'main.dart'; void javascriptHandler() { final shouldSkip = kIsWeb ? true : ![ TargetPlatform.android, TargetPlatform.iOS, TargetPlatform.macOS, ].contains(defaultTargetPlatform); skippableTestWidgets('JavaScript Handler', (WidgetTester tester) async { final Completer controllerCompleter = Completer(); final Completer pageStarted = Completer(); final Completer pageLoaded = Completer(); final Completer handlerFoo = Completer(); final Completer handlerFooWithArgs = Completer(); final List messagesReceived = []; await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: InAppWebView( key: GlobalKey(), initialFile: "test_assets/in_app_webview_javascript_handler_test.html", onWebViewCreated: (controller) { controllerCompleter.complete(controller); controller.addJavaScriptHandler( handlerName: 'handlerFoo', callback: (args) { handlerFoo.complete(); return Foo(bar: 'bar_value', baz: 'baz_value'); }); controller.addJavaScriptHandler( handlerName: 'handlerFooWithArgs', callback: (args) { messagesReceived.add(args[0] as int); messagesReceived.add(args[1] as bool); messagesReceived.add(args[2] as List?); messagesReceived.add( args[3]?.cast() as Map?); messagesReceived.add( args[4]?.cast() as Map?); handlerFooWithArgs.complete(); }); }, initialSettings: InAppWebViewSettings(javaScriptEnabled: true), onLoadStart: (controller, url) { pageStarted.complete(); }, onLoadStop: (controller, url) { pageLoaded.complete(); }, ), ), ); await pageStarted.future; await pageLoaded.future; await handlerFoo.future; await handlerFooWithArgs.future; expect(messagesReceived[0], 1); expect(messagesReceived[1], true); expect(listEquals(messagesReceived[2] as List?, ["bar", 5]), true); expect(mapEquals(messagesReceived[3], {"foo": "baz"}), true); expect( mapEquals( messagesReceived[4], {"bar": "bar_value", "baz": "baz_value"}), true); }, skip: shouldSkip); }