Firebase Dynamic Link with navigate cause infinity loop

Viewed 508

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;
  }
1 Answers

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
Related