简体   繁体   English

Firebase 动态链接与导航导致无限循环

[英]Firebase Dynamic Link with navigate cause infinity loop

I created a firebase dynamic link from Firebase Console.我从 Firebase 控制台创建了一个 firebase 动态链接。 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.我已经尝试在我的代码中实现它,当我通过使用导航方法单击example.page.link/ABCD冷启动我的应用程序时,它会导致无限循环。 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示例链接: 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;
  }

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).我不应该使用导航推送,因为这条路线“/Pages”将重新创建页面并一次又一次地运行firebaseDynamicLinkInit() (无限循环)。

The route '/Pages' initState() include firebaseDynamicLinkInit() causes infinity loop.路由 '/Pages' initState()包括 firebaseDynamicLinkInit( )导致无限循环。

 // 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

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

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