Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda