How to detect url_launcher disapear

102 views Asked by At

I have used launchUrl(uri); of url_launcher package to open a webview.

I want to detect when the user taps to 'Done' or Webview of url_launcher disappears.

How can I make it?

1

There are 1 answers

0
elblasy On

You can use WidgetsBindingObserver interface and listen for widget state changes. This will let you know if your app is in the background or foreground. So you can use the resumed case to run code after your return from the browser.

class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
  AppLifecycleState _notification; 
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch(state){
      case AppLifecycleState.resumed:
        print("app in resumed");
        break;
      case AppLifecycleState.inactive:
        print("app in inactive");
        break;
      case AppLifecycleState.paused:
        print("app in paused");
        break;
      case AppLifecycleState.detached:
        print("app in detached");
        break;
      case AppLifecycleState.hidden:
        print("app in hidden");
        break;
    }
  }

  @override
  initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    ...
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}