7

I'm using firebase_dynamic_links for passwordless login with firebase and getInitialLink() is always returning null on version 0.5.0+8. If I use version 0.4.0+4 and retrieveDynamicLink() instead of getInitialLink() it works fine.

Since it's working in version 0.4.0+4 I assume the problem is not on Firebase settings. This is how I'm sending the email:

final FirebaseAuth user = FirebaseAuth.instance;
    try {
      user.sendSignInWithEmailLink(
          email: _email,
          androidInstallIfNotAvailable: true,
          iOSBundleID: "com.mydomain.myappname",
          androidMinimumVersion: "16",
          androidPackageName: "com.mydomain.myappname",
          url: "https://myAppName.page.link/fJc4",
          handleCodeInApp: true);
    } catch (e) {
      _showDialog(e.toString());
      return false;
    }

And then to retrieve it:

@override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      _retrieveDynamicLink();
    }
  }

  Future<void> _retrieveDynamicLink() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    print('data == ' + data.toString());

    final Uri deepLink = data?.link;
    print(deepLink.toString());

    if (deepLink != null) {
      _link = deepLink.toString();
      _signInWithEmailAndLink();
    }
    return deepLink.toString();
  }

data is always null on the new version with getInitialLink(). It works on the previous version with retrieveDynamicLink().

I created a new project just to test it and the problem persists. The only other change I made to the project, besides the view files was add firebase_auth: ^0.15.0+1 to pubspc.yaml

Doctor summary (to see all details, run flutter doctor -v): [√]

Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 10.0.17763.864], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android SDKversion 28.0.3)

[√] Android Studio (version 3.5)

[!] VS Code (version 1.40.0) X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)

! Doctor found issues in 1 category.

Any help is appreciated.

Community
  • 1
  • 1
Dpedrinha
  • 3,741
  • 3
  • 38
  • 57

3 Answers3

6

getInitialLink() only works if opened via a dynamic link (see plugin document), not when the application is active or in background (for this you need to call onLink).

  void initDynamicLinks() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri deepLink = data?.link;    if (deepLink != null) {
      Navigator.pushNamed(context, deepLink.path);
    }

    FirebaseDynamicLinks.instance.onLink(
      onSuccess: (PendingDynamicLinkData dynamicLink) async {
        final Uri deepLink = dynamicLink?.link;

        if (deepLink != null) {
          Navigator.pushNamed(context, deepLink.path);
        }
      },
      onError: (OnLinkErrorException e) async {
        print('onLinkError');
        print(e.message);
      }
    );
  }
Nick
  • 138,499
  • 22
  • 57
  • 95
WilsonWan
  • 104
  • 1
  • 5
6

please you may use this plugin instead app_links

because firebase_dynamic_links has bugs at the moment.

Mohammed_7aafar
  • 385
  • 1
  • 6
  • 9
  • 1
    It's true, I dropped in app_links as a replacement and it works without issues. There is something wrong with Firebase Dynamic Links. – Matthew Rideout Jun 17 '22 at 04:57
  • 1
    I filed an issue [here](https://github.com/firebase/flutterfire/issues/8926) but the last few issues for this same bug were closed without resolution. – Matthew Rideout Jun 17 '22 at 05:12
  • 1
    I spend a few hours on it, but eventually went with app_links and had it working in 10 minutes for all use cases. Dynamic_links has lots of bugs and the documentation isn't the best – Yonkee May 12 '23 at 22:50
0

ensure that you get started dynamic link in firebase projectenter image description here