Dpedrinha
Dpedrinha

Reputation: 4220

FirebaseDynamicLinks.instance.getInitialLink() always returning null on Android

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.

Upvotes: 7

Views: 6064

Answers (3)

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

Upvotes: 1

Mohammed_7aafar
Mohammed_7aafar

Reputation: 475

please you may use this plugin instead app_links

because firebase_dynamic_links has bugs at the moment.

Upvotes: 6

WilsonWan
WilsonWan

Reputation: 124

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

Upvotes: 7

Related Questions