简体   繁体   中英

Flutter firebase dynamic link not listening

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 }); }

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

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.

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();
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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