【问题标题】:Firebase Dynamic Link with navigate cause infinity loopFirebase 动态链接与导航导致无限循环
【发布时间】:2020-11-30 16:33:48
【问题描述】:

我从 Firebase 控制台创建了一个 firebase 动态链接。我已经尝试在我的代码中实现它,当我通过使用导航方法单击 example.page.link/ABCD 冷启动我的应用程序时,它会导致无限循环。如果应用程序在后台,则没有任何问题。

问题: 当应用程序从冷启动并导航到新页面时触发无限循环。

知道如何解决这个问题吗?

编辑

示例链接: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;
  }

【问题讨论】:

  • 能否分享部分代码。
  • @AjayKumar 我已经用代码编辑了帖子。你现在可以看看。谢谢。

标签: firebase flutter dart firebase-dynamic-links


【解决方案1】:

线程关闭

我为我的粗心道歉。

我发现了我犯的错误。我不应该使用导航推送,因为这条路线“/Pages”将重新创建页面并一次又一次地运行 firebaseDynamicLinkInit()(无限循环)。

路由 '/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

【讨论】:

  • 不确定这是否是正确的方法。 getInitialLink() 文档说它在第一次尝试后返回 null。
猜你喜欢
  • 2022-11-14
  • 1970-01-01
  • 2022-01-15
  • 2013-10-07
  • 2020-08-27
  • 2021-05-07
  • 2012-08-24
  • 2020-11-16
相关资源
最近更新 更多