Firebase Dynamic Link with navigate cause infinity loop

451

THREAD CLOSED

I apologize for my carelessness.

I found the mistake i'd made. I shouldn't use navigate push because this route '/Pages' will recreate the page and run the firebaseDynamicLinkInit() again and again (infinity loop).

The route '/Pages' initState() include firebaseDynamicLinkInit() causes infinity loop.

 // START This part trigger the problem
 Navigator.of(context).popUntil((route) => route.isFirst);
 Navigator.of(context).pushReplacementNamed('/Pages', arguments: 6);
 // END This part trigger the problem
Share:
451
YeN
Author by

YeN

Hello everyone.

Updated on December 23, 2022

Comments

  • YeN
    YeN over 1 year

    I created a firebase dynamic link from Firebase Console. I've tried implement it to my code and when I cold start my app by clicking the example.page.link/ABCD with navigate method it cause an infinity loop. If the app is in background it doesn't have any issue.

    Problem : The infinity loop trigger when the app from cold start with navigate to new page.

    Any idea how to resolve this issue ?

    Edited

    Example link : www.example.com/testing?title=testing_deep_link

      Future firebaseDynamicLinkInit() async {
        final PendingDynamicLinkData data =
            await FirebaseDynamicLinks.instance.getInitialLink();
        _handleDeepLink(data);
    
        FirebaseDynamicLinks.instance.onLink(
            onSuccess: (PendingDynamicLinkData dynamicLinkData) async {
          _handleDeepLink(dynamicLinkData);
        }, onError: (OnLinkErrorException e) async {
          print('${e.message}');
        });
      }
    
      void _handleDeepLink(PendingDynamicLinkData data) {
        final Uri deepLink = data?.link;
        if (deepLink != null) {
          var title = deepLink.queryParameters['title'];
    
          if (title != null) {
            // START This part trigger the problem
            Navigator.of(context).popUntil((route) => route.isFirst);
            Navigator.of(context).pushReplacementNamed('/Pages', arguments: 6);
            // END This part trigger the problem
          }
        }
    
        return null;
      }
    
    • Ajay Kumar
      Ajay Kumar over 3 years
      Can you share some part of the code.
    • YeN
      YeN over 3 years
      @AjayKumar I've edited the post with code. You can have a look now. Thanks.
  • sjsam
    sjsam over 3 years
    Not sure if this is the right approach. The getInitialLink() documentation says it returns null after the first attempt.