简体   繁体   中英

How to listen to the Flutter in-app web browser?

I am using the flutter_web_browser package from Flutter to open a web browser inside the app. I want to navigate to another page when the browser window closes. The function openWebPage is of type Future, so I've tried using then() and whenComplete(), but neither of these functions are entered when I close the browser manually or the browser closes using deep links.

final url = "https://google.com";

    return Container(
      color: Colors.white,
      child: FlatButton(
        child: Text("Click ME"),
        onPressed: () async {
           await FlutterWebBrowser.openWebPage(
            url: "$url",
            androidToolbarColor: Colors.deepPurple,
          ).whenComplete(() {
            print('OVER');
          });
        },
      ),
    );

How do I get the app to listen to when the browser closes and navigate to another screen accordingly?

Since you are going out of the app( which is pause on App lifecycles) you cannot listen to whats happening on the background or some other app. As a work around you can Listen to app life cycles and do the Navigation. Flutter App Life Cycles , Flutter App Life Cycles Implementation .

Or else you can use the In-App web browser which consists of the functionality you needed. Flutter In app web browser

Hope this helps!

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