How to receive value from webVew button action in inAppWeview Flutter

Issue

I have two buttons on the webpage see the image below

I have two buttons on the webpage see the image below

I try

onWebViewCreated: (InAppWebViewController controller) {
    webView = controller;
    webView.addJavaScriptHandler(handlerName: "performClick", callback: (value){
      print("value ==="+value.toString());
    });
  },

But unable to receive the data.

I did it in android native see the below code in kotlin that works for me

  webviewTaskPost.addJavascriptInterface(object : Any() {
        @JavascriptInterface           // For API 17+
        fun performClick(parameter: String) {

            if (parameter == "1") {
                submittedCaseApplication()
            } else if (parameter == "2") {
                showMyTaskList()
            }
            //Toast.makeText(this@MainActivity, strl, Toast.LENGTH_SHORT).show()
        }
    }, "ok")

How can I receive value in dart flutter like an android native?

Solution

onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
webView.addJavaScriptHandler(handlerName: "Back", callback: (value){
  print("value ==="+value.toString());
});

This Way is ok, I updated my web look how I update my Button Click

enter image description here

Answered By – Imran Sk

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.