Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
flutter inappwebview is not printing on console

i was establishing communication between website and flutter i want to fire message on button click and i have implemented the code below.

 <button onclick="buttonClick()" type="button">Cancel</button>

<script>

        function buttonClick() {

       window.addEventListener("flutterInAppWebViewPlatformReady", function(event) {

             window.flutter_inappwebview.callHandler('cancelbuttonState', 1, true,['msg','CancelbuttonClicked'], {test:'Go-Back'}).then(function(result) {
            
             alert("Hello! Cancel Buttton clicked!!");
              console.log('Hello! Cancel Buttton clicked!!');

             });
           });
          
         }
       </script>

in flutter side i have implemented the following to get the message

controller.addJavaScriptHandler(
                    handlerName: "cancelbuttonState",
                    callback: (args) async {
                      print('Cancel Button clicked');
              
                      return args.reduce((curr, next) => curr + next);
                    });

but both JavaScript and app dint give me console print thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are executing the below line too late inside the body of the cancel function. You will need to add the listener much earlier for the callback to be registered.

In other words, you are listening for an event that is already finished.

window.addEventListener("flutterInAppWebViewPlatformReady" .....

Reorganize your code in a fashion similiar to this:

<button onclick="buttonClick()" type="button">Cancel</button>
<script>
    isAppReady = false;
    window.addEventListener("flutterInAppWebViewPlatformReady", function (event) {
        isAppReady = true;
    });
    function buttonClick() {
        if (isAppReady) {
            window.flutter_inappwebview.callHandler('cancelbuttonState', 1, true, ['msg', 'CancelbuttonClicked'], { test: 'Go-Back' }).then(function (result) {
                alert("Hello! Cancel Buttton clicked!!");
                console.log('Hello! Cancel Buttton clicked!!');
            });
        }
    }
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda