I am trying to load an HTML form in a webview that has some callbacks on button clicks which I am trying to handle in a javascript handler but are not getting invoked.
Library used
flutter_inappwebview: ^5.7.1
This is how I defined the webview.
InAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
ios: IOSInAppWebViewOptions(
allowsInlineMediaPlayback: true,
)
),
initialUrlRequest: URLRequest(
url: Uri.dataFromString(
'about:blank',
mimeType: 'text/html',
)),
onWebViewCreated: (controller) {
controller.addJavaScriptHandler(
handlerName: 'showToast',
callback: (data) {
AppUtils.showMessage(data);
print('data -$data');
});
setState((){
_controller = controller;
});
loadForm();
},
onLoadStop: (controller,uri){
},
onConsoleMessage: (controller, message) {
print('on Console message - $message');
},
)
And in load form I am using an html page which looks like
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<script>
isAppReady = false;
window.addEventListener("flutterInAppWebViewPlatformReady", function (event) {
isAppReady = true;
});
function buttonClick() {
if (isAppReady) {
window.flutter_inappwebview.callHandler('showToast', 'result');
}
}
</script>
<body>
<button onclick="buttonClick()" type="button">Show</button>
</body>
</html>
Now The event listener is never invoked hence the boolean value is app ready and is not changed. Any help regarding why it is not getting invoked is appreciated
