I’m using Firebase Dynamic Links in my Flutter application. When I click a dynamic link, the app opens perfectly, but I’m unable to retrieve the link in my main()
function.
My Setup
pubspec.yaml
Dependencies
dependencies:
flutter:
sdk: flutter
firebase_core: ^latest_version
firebase_dynamic_links: ^latest_version
void initDynamicLinks() async {
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData? dynamicLink) async {
final Uri? deepLink = dynamicLink?.link;
if (deepLink != null) {
// Handle the deep link
print('Received deep link: $deepLink');
if (deepLink.path == '/add') {
// Navigate to a specific page or perform an action
Navigator.pushNamed(context, '/addPage');
}
}
},
onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
},
);
final PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink();
if (initialLink != null) {
final Uri? deepLink = initialLink.link;
if (deepLink != null) {
// Handle the deep link
print('Received initial link: $deepLink');
if (deepLink.path == '/add') {
// Navigate to a specific page or perform an action
Navigator.pushNamed(context, '/addPage');
}
}
}
}
- Verified that the dynamic link domain is correctly set in the Firebase console.
- Ensured the dependencies in pubspec.yaml are up-to-date.
- Checked the configuration in Info.plist for iOS.
- Printed logs in the initDynamicLinks function to debug.