Issue
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.
Solution
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);
}
);
}
Answered By - WilsonWan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.