简体   繁体   English

如何收听 Flutter 应用内网页浏览器?

[英]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.我正在使用 Flutter 中的 flutter_web_browser 包在应用程序内打开网络浏览器。 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.函数openWebPage是 Future 类型,所以我尝试使用 then() 和 whenComplete(),但是当我手动关闭浏览器或浏览器使用深层链接关闭时,这两个函数都没有输入。

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 . Flutter 应用生命周期Flutter 应用生命周期实现

Or else you can use the In-App web browser which consists of the functionality you needed.或者,您可以使用包含您需要的功能的应用内网络浏览器。 Flutter In app web browser Flutter In 应用程序网络浏览器

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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