Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when webview url changes in flutter?

I have been looking around for a webview plugin in flutter that can detect when the url changes, but didn't find a match? The reason I am trying to detect a url change is because I want to change a bool variable to true when changed, which will then change the color of a appbar, is this possible?Are there any simple/easy examples out there that can achieve what i'm looking for? Thanks for any help in advance!

like image 817
Steve Avatar asked Dec 31 '22 18:12

Steve


1 Answers

You can use StreamSubscription.

  StreamSubscription<String> _onStateChanged;
  final flutterWebviewPlugin = new FlutterWebviewPlugin();

      @override
      void initState() {
        super.initState();
    
        _onStateChanged =
            flutterWebviewPlugin.onUrlChanged.listen((String state) async {
          if (state.startsWith('your_url')) {
                // do whatever you want 
           }
        });
      }
like image 126
John Joe Avatar answered Jan 06 '23 13:01

John Joe