简体   繁体   中英

Flutter Dynamic Link triggers everytime I open app

I followed the guide below to set up dynamic links on my flutter project. The dynamic link works and takes me to the desire location in the app but the issue is that everytime I reopen the app, the dynamic link is triggered again. The code block below is what triggers the link when the app is resumed. What do I have to do for the app to know that if the link is not being clicked, dont take me to the dynamics link location?

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) async{
    if (state == AppLifecycleState.resumed) {
      _timerLink = new Timer(
        const Duration(milliseconds: 1000),
            () {
           _dynamicLinkService.retrieveDynamicLink(context);
        },
      );
    }
  }

Source: Firebase-flutter-dynamic-links-step-by-step-guide

   @override
   void initState() {
     super.initState();
     WidgetsBinding.instance.addObserver(this);
     //calls the link on app, from app closed
     _dynamicLinkService.initDynamicLinks(context);
     WidgetsBinding.instance.removeObserver(this); 
   }

I had the same problem, it seemed to be coming from my call in initState though. I solved it by removing the observer after the dynamicLinkService call.

I also have the didChangeAppLifecycleState method which is responsible for the Deeplink when the app is open.

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