@@ -825,9 +825,6 @@ class InAppWebViewEIP1193 extends StatefulWidget {
825825}
826826
827827class _InAppWebViewEIP1193State extends State <InAppWebViewEIP1193 > {
828- ///Constant message additional receive
829- final _alertTitle = "messagePayTube" ;
830-
831828 /// Script provider will inject in web app
832829 String ? jsProviderScript;
833830
@@ -872,7 +869,9 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
872869 var config = $paramConfig ;
873870 window.ethereum = new ${widget .customWalletName }.Provider(config);
874871 ${widget .customWalletName }.postMessage = (jsonString) => {
875- alert("$_alertTitle " + JSON.stringify(jsonString || "{}"))
872+ if (window.flutter_inappwebview.callHandler) {
873+ window.flutter_inappwebview.callHandler('handleRequestEIP1193', JSON.stringify(jsonString));
874+ }
876875 };
877876 })();
878877 """ ;
@@ -937,6 +936,12 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
937936 contextMenu: widget.contextMenu,
938937 onWebViewCreated: (controller) async {
939938 _webViewController = controller;
939+ controller.addJavaScriptHandler (
940+ handlerName: 'handleRequestEIP1193' ,
941+ callback: (args) {
942+ _jsBridgeCallBack (args[0 ]);
943+ },
944+ );
940945 widget.onWebViewCreated? .call (controller);
941946 },
942947 onLoadStart: (controller, url) async {
@@ -962,24 +967,7 @@ class _InAppWebViewEIP1193State extends State<InAppWebViewEIP1193> {
962967 onLoadResourceCustomScheme: widget.onLoadResourceCustomScheme,
963968 onCreateWindow: widget.onCreateWindow,
964969 onCloseWindow: widget.onCloseWindow,
965- onJsAlert: widget.onJsAlert ??
966- (controller, request) {
967- final message = request.message;
968- bool handledByClient = false ;
969- if (message? .contains (_alertTitle) == true ) {
970- handledByClient = true ;
971- _jsBridgeCallBack (
972- request.message! .replaceFirst (_alertTitle, "" ),
973- );
974- }
975-
976- return Future .value (
977- JsAlertResponse (
978- message: message ?? "" ,
979- handledByClient: handledByClient,
980- ),
981- );
982- },
970+ onJsAlert: widget.onJsAlert,
983971 onJsConfirm: widget.onJsConfirm,
984972 onJsPrompt: widget.onJsPrompt,
985973 onReceivedHttpAuthRequest: widget.onReceivedHttpAuthRequest,
0 commit comments