简体   繁体   中英

How to close web-view automatically when URL changed in Android Flutter?

I want to close Web-View Automatically when URL is Changed. Here is the code i'm used to open a web-view in Flutter Android Application.

 GestureDetector(
              child: WebviewScaffold(
                url: webUrl,
                withJavascript: true,
                withLocalStorage: true,
                persistentFooterButtons: <Widget>[
                  RaisedBtn(
                    onPressed: (){
                      Screen();
                      flutterWebviewPlugin.dispose();
                    },
                    text: "Confirm",
                  )
                ],
              ),
            ),

please check example below. Flutter webview has single instance which you can retrieve as FlutterWebviewPlugin()

 import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

    final _loginWebView = FlutterWebviewPlugin();

    _onUrlChanged = _loginWebView.onUrlChanged.listen((String url) {
            //check is it right url for navigation and navigate back or do nothing
        });

Important! Do not forget to dispose it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM