Flutter firebase 动态链接未监听

发布于 2025-01-13 22:44:48 字数 772 浏览 0 评论 0原文

我正在尝试在 flutter 应用程序中实现 Firebase 动态链接。当我单击链接时,它会打开应用程序,但不会调用监听函数。

我根据 FlutterFire 一步步重新配置,所以我认为问题不在于配置,但可能在于我使用插件的方式,因为没有关于该插件最新版本的文档。

当我使用其他服务时,Firebase 在我的应用程序中正确初始化。

我正在 android 模拟器上进行测试

我正在尝试使用以下代码监听来自有状态小部件的动态链接

我首先导航到包含此小部件的页面,然后我将应用程序设置为后台,我单击链接,应用程序在同一个地方打开,但没有任何反应。

  @override
  void initState() {
    super.initState();
    initLink();
  }

  void initLink() {
    FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {
      print('dynamic link');
      print(dynamicLinkData.toString());
      // Navigator.pushNamed(context, dynamicLinkData.link.path);
    }).onError((error) {
      // Handle errors
    });
  }

I am trying to implement Firebase Dynamic links in a flutter app. When I click on the link it opens the app but doesn't call the listen functions.

I reconfigured step by step according to FlutterFire, so I don't think the issue is in configuration, but maybe in the way I'm using the plugin as there is no documentation on the last version of the plugin.

Firebase is correctly initialised in my app as I'm using other services.

I'm doing tests on android simulator

I'm trying to listen the dynamic link from a stateful widget with the following code

I'm first navigating to the page containing this widget, then I background the app, I click on the link, the app opens at the same place and nothing happens.

  @override
  void initState() {
    super.initState();
    initLink();
  }

  void initLink() {
    FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {
      print('dynamic link');
      print(dynamicLinkData.toString());
      // Navigator.pushNamed(context, dynamicLinkData.link.path);
    }).onError((error) {
      // Handle errors
    });
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌酱 2025-01-20 22:44:48

这里有一个未解决的问题 https://github.com/FirebaseExtended/flutterfire/issues/8261< /a> 其他一些人也有同样的问题,包括我自己。

目前看来,odlund 发布了至少能让事情再次正常运行的临时解决方案。如果您进行这些更改,监听器应该会再次工作,直到我们有更多的官方修复:
https://github.com/FirebaseExtended/flutterfire/commit/8bb4bee7e678241e75ab37a2bcfa0831426b91fa

There is an open issue here https://github.com/FirebaseExtended/flutterfire/issues/8261 where a few others are having the same problem including myself.

It seems for now the temporary solution to at least getting things working again is posted by odlund. If you make these changes the listener should work again until we have more of an official fix:
https://github.com/FirebaseExtended/flutterfire/commit/8bb4bee7e678241e75ab37a2bcfa0831426b91fa

我的影子我的梦 2025-01-20 22:44:48

请将 firebase_dynamic_links 更新至 4.1.1。似乎是 4.1.0 或更早版本的问题,其中 FirebaseDynamicLinks.instance.onLink.listen 不起作用

您无需检查应用程序是否正常在后台或恢复以使其正常工作。

Please update firebase_dynamic_links to 4.1.1. Seems to be an issue with the version 4.1.0 or earlier where FirebaseDynamicLinks.instance.onLink.listen doesn't work

You don't need to check if the app is in the background or resumed for this to work.

み青杉依旧 2025-01-20 22:44:48

这非常有效!

class _MainAppState extends State<MainApp> {  

Future<void> initDynamicLinks() async {
    print("Initial DynamicLinks");
    FirebaseDynamicLinks dynamicLinks = FirebaseDynamicLinks.instance;

    // Incoming Links Listener
    dynamicLinks.onLink.listen((dynamicLinkData) {
      final Uri uri = dynamicLinkData.link;
      final queryParams = uri.queryParameters;
      if (queryParams.isNotEmpty) {
        print("Incoming Link :" + uri.toString());
        //  your code here
      } else {
        print("No Current Links");
        // your code here
      }
    });

    // Search for Firebase Dynamic Links
    PendingDynamicLinkData? data = await dynamicLinks
        .getDynamicLink(Uri.parse("https://yousite.page.link/refcode"));
    final Uri uri = data!.link;
    if (uri != null) {
      print("Found The Searched Link: " + uri.toString());
      // your code here
    } else {
      print("Search Link Not Found");
      // your code here
    }

  }

  Future<void> initFirebase() async {
    print("Initial Firebase");
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    // await Future.delayed(Duration(seconds: 3));
    initDynamicLinks();
  }

  @override
  initState() {
    print("INITSTATE to INITIALIZE FIREBASE");
    super.initState();
    initFirebase();
  }

This Works Perfectly!

class _MainAppState extends State<MainApp> {  

Future<void> initDynamicLinks() async {
    print("Initial DynamicLinks");
    FirebaseDynamicLinks dynamicLinks = FirebaseDynamicLinks.instance;

    // Incoming Links Listener
    dynamicLinks.onLink.listen((dynamicLinkData) {
      final Uri uri = dynamicLinkData.link;
      final queryParams = uri.queryParameters;
      if (queryParams.isNotEmpty) {
        print("Incoming Link :" + uri.toString());
        //  your code here
      } else {
        print("No Current Links");
        // your code here
      }
    });

    // Search for Firebase Dynamic Links
    PendingDynamicLinkData? data = await dynamicLinks
        .getDynamicLink(Uri.parse("https://yousite.page.link/refcode"));
    final Uri uri = data!.link;
    if (uri != null) {
      print("Found The Searched Link: " + uri.toString());
      // your code here
    } else {
      print("Search Link Not Found");
      // your code here
    }

  }

  Future<void> initFirebase() async {
    print("Initial Firebase");
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    // await Future.delayed(Duration(seconds: 3));
    initDynamicLinks();
  }

  @override
  initState() {
    print("INITSTATE to INITIALIZE FIREBASE");
    super.initState();
    initFirebase();
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文