1

Im using the flutter plugin "flutter_webview_plugin" for open an URL inside my app. The problem, is when in Android, you press the back button, it "returns" and show the progress indicator infinitely on the WebViewScaffold until you press again the back button.

I tried adding this code within builder function:

    flutterWebviewPlugin.onDestroy.listen((_) {
        if (Navigator.canPop(context)) {
          Navigator.of(context).pop();
          flutterWebviewPlugin.dispose();
          flutterWebviewPlugin.cleanCookies();
        }
      });

It works for the "first" time i call my function. But, on the second, it happens again.

_launchURL() async {
    String url = result;
    if (await canLaunch(url)) {
      Navigator.of(context).push(MaterialPageRoute(
          builder: (ctx) => WebviewScaffold(
                clearCache: true,
                clearCookies: true,
                withLocalStorage: false,
                appCacheEnabled: false,
                initialChild: Center(child: CircularProgressIndicator()),
                url: url,
                appBar: AppBar(title: Text("Fichas DoggyStyle")),
              )));
      flutterWebviewPlugin.onDestroy.listen((_) {
        if (Navigator.canPop(context)) {
          Navigator.of(context).pop();
          flutterWebviewPlugin.dispose();
          flutterWebviewPlugin.cleanCookies();
        }
      });
    } else {
      throw 'No pudimos abrir la ficha :(';
    }
  }

1 Answer 1

1

Try calling flutterWebviewPlugin.onDestroy.listen() inside the initstate() of a widget... it works fine for me...

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.