Flutterfire: [firebase_dynamic_links] getInitialLink() not working on Android on version 0.5.0+8

Created on 28 Nov 2019  Â·  6Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug
I'm using 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.

To Reproduce
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().

Expected behavior
Get a non null link

Additional context
I'm testing it on Android. I haven't tested for iOS yet.

Here's the flutter doctor:

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 SDK version 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.

crowd dynamic_links regression bug

Most helpful comment

Same issue on iOS. On Android all OK.

All 6 comments

On my iOS devices with iOS version 10 and 12 I had to implement a short delay after appstart before calling getInitialLink(), otherwise it returned null. Havent tested how long this delay has to be, but with a 2 second delay it works. Tested both with v1.7.8.hotfix+4 and 1.9.1.hotfix+6

Tested with 0.5.0+6 and 0.5.0+8, didnt work without the delay

@gisinator I saw this workaround somewhere else but it doesn't work for Android. Tried with 3 seconds delay and the problem persists.

Same issue on iOS. On Android all OK.

Firebase 0.6.0, same on iOS.
getInitialLink() returns null time to time but pretty often.

But,

I have noticed that if to do not click the same link like crazy and leave it alone for something like 2 minutes then it works a way better (always actually in my case). Could be some sort of protection on dynamic links itself. Or maybe it's also related to initialisation of Firebase.instance. But I am not sure :-)


flutter doctor -v
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G2021, locale en-GB)
• Flutter version 1.20.2 at /Users/alsk/Library/flutter
• Framework revision bbfbf1770c (11 days ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/alsk/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.6, Build version 11E708
• CocoaPods version 1.9.1

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Community Edition (version 2020.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 48.1.4
• Dart plugin version 202.6397.47

[✓] VS Code (version 1.46.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.12.1

Hey @allco, @sanekyy you could try https://github.com/FirebaseExtended/flutterfire/pull/3567 - I experienced with same problem in ios and found a reason when the initial link is being overwritten by null later so there is a race condition...

Hello @madmag77. Your PR works great. Thanks.

Was this page helpful?
0 / 5 - 0 ratings