🐛 [dynamic_links] getInitialLink() is always returning null (on Android)
Bug report
getInitialLink() is always returning null (on Android). I have spends hours already searching for it, read multiple posts about this issue and tried all things I could find, but it always stays null.
I tried:
- Using a delay of 2 seconds
- Listen to onLink to see if that's working
- Trying it in different places in the app
- Trying it in debug and release mode
I unfortunately never got it working. It is currently implemented this way:
// first wait 2 seconds, then retrieve dynamic link
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_timerLink = Timer(
const Duration(milliseconds: 2000),
() {
Provider.of<EventBloc>(context, listen: false)
.retrieveDynamicLink(context);
},
);
}
}
Future<void> retrieveDynamicLink(BuildContext context) async {
final PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getInitialLink();
if (data != null) {
Uri? deepLink = data.link;
print(deepLink.path);
}
}
Steps to reproduce
Steps to reproduce the behavior:
- Implement above logic
- Generate dynamic link
- Click on dynamic link, app opens
- Data is always null
Expected behavior
- Data contains data :)
Additional context
I have not tested it on iOS.
Flutter doctor
Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.2.1 21D62 darwin-x64, locale nl-NL)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.65.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
Flutter dependencies
Click To Expand
Dart SDK 2.16.1
Flutter SDK 2.10.2
vibed_app 1.0.0+21
dependencies:
- animated_icon_button 1.0.2 [flutter freezed_annotation]
- cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- cloud_firestore 3.1.10 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.4
- device_calendar 4.2.0 [flutter collection sprintf timezone flutter_native_timezone]
- device_info 2.0.3 [flutter device_info_platform_interface]
- dots_indicator 2.1.0 [flutter]
- firebase_analytics 9.1.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 3.3.10 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.13.1 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_dynamic_links 4.0.0 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
- firebase_storage 10.2.9 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- flutter 0.0.0 [characters collection material_color_utilities meta typed_data vector_math sky_engine]
- flutter_calendar_carousel 2.1.0 [intl flutter]
- flutter_form_builder 6.2.0 [flutter flutter_localizations intl collection]
- flutter_launcher_icons 0.9.2 [args image path yaml]
- flutter_login_facebook 1.4.1 [flutter list_ext]
- flutter_reorderable_list 1.2.0 [flutter]
- font_awesome_flutter 9.2.0 [flutter]
- google_sign_in 5.2.4 [flutter google_sign_in_platform_interface google_sign_in_web]
- image_cropper 1.5.0 [flutter]
- image_picker 0.8.4+11 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- intl 0.17.0 [clock path]
- legacy_buttons 0.0.1 [flutter]
- linkable 3.0.1 [flutter url_launcher]
- onesignal_flutter 3.3.0 [flutter]
- path_provider 2.0.9 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- photo_view 0.13.0 [flutter]
- provider 6.0.2 [collection flutter nested]
- share_plus 3.1.0 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web]
- timeago 3.2.2
- url_launcher 6.0.20 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
dev dependencies:
- flutter_lints 1.0.4 [lints]
- flutter_native_splash 2.1.0 [args image js meta path xml yaml universal_io flutter flutter_web_plugins]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph typed_data]
transitive dependencies:
- archive 3.2.2 [crypto path]
- args 2.3.0
- async 2.8.2 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- cloud_firestore_platform_interface 5.5.1 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.6.10 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.15.0
- cross_file 0.3.2 [flutter js meta]
- crypto 3.0.1 [collection typed_data]
- device_info_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- fake_async 1.2.0 [clock collection]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase_analytics_platform_interface 3.1.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.0+8 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.2.1 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 3.3.9 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.2.5 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.6.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_dynamic_links_platform_interface 0.2.2 [firebase_core flutter meta plugin_platform_interface]
- firebase_storage_platform_interface 4.1.1 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.2.10 [async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- flutter_blurhash 0.6.4 [flutter]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path typed_data vector_math]
- flutter_native_timezone 2.0.0 [flutter_web_plugins flutter js]
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta typed_data vector_math]
- freezed_annotation 1.1.0 [collection json_annotation meta]
- google_sign_in_platform_interface 2.1.2 [flutter quiver]
- google_sign_in_web 0.10.0+5 [flutter flutter_web_plugins google_sign_in_platform_interface js]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image 3.1.3 [archive meta xml]
- image_picker_for_web 2.1.6 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_platform_interface 2.4.4 [cross_file flutter http plugin_platform_interface]
- js 0.6.3
- json_annotation 4.4.0 [meta]
- lints 1.0.1
- list_ext 1.0.4 [quiver collection]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.3
- meta 1.7.0
- mime 1.0.1
- nested 1.0.0 [flutter]
- octo_image 1.0.1 [flutter flutter_blurhash]
- path 1.8.0
- path_provider_android 2.0.12 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.8 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.5 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.5 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.3 [flutter platform plugin_platform_interface]
- path_provider_windows 2.0.5 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- petitparser 4.4.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- quiver 3.0.1+1 [matcher]
- rxdart 0.27.3
- share_plus_linux 2.0.4 [share_plus_platform_interface file flutter meta url_launcher]
- share_plus_macos 2.0.2 [share_plus_platform_interface flutter]
- share_plus_platform_interface 2.0.1 [flutter meta mime plugin_platform_interface]
- share_plus_web 2.0.4 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta]
- share_plus_windows 2.0.3 [share_plus_platform_interface flutter meta url_launcher]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- sprintf 6.0.0
- sqflite 2.0.2 [flutter sqflite_common path]
- sqflite_common 2.2.0 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0
- term_glyph 1.2.0
- test_api 0.4.8 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timezone 0.8.0 [path]
- typed_data 1.3.0 [collection]
- universal_io 2.0.4 [collection crypto meta typed_data]
- url_launcher_android 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.15 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.0 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.0.5 [flutter plugin_platform_interface]
- url_launcher_web 2.0.9 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.0 [flutter url_launcher_platform_interface]
- uuid 3.0.6 [crypto]
- vector_math 2.1.1
- win32 2.4.1 [ffi]
- xdg_directories 0.2.0+1 [meta path process]
- xml 5.3.1 [collection meta petitparser]
- yaml 3.1.0 [collection source_span string_scanner]
We had the same issue, pretty sure the PR above fixes it.
we are in the same, I have tried everything but it always returns null, therefore it does not enter the if
same problem
Same on iOs and Android. Not only with getInitialLink() but also with onLink.listen(). In FirebaseDynamicLinks.instance.onLink.listen(), the listen is never triggered.
I can confirm I'm experiencing the same thing but @odlund PR does in fact fixed the issue I was having. Unfortunately since this isn't implemented I had to manually edit the files myself to match the below link but of course that's not always suggested as things can get overwritten.
https://github.com/FirebaseExtended/flutterfire/pull/8263/commits/8bb4bee7e678241e75ab37a2bcfa0831426b91fa
I had the same problem with onLink (Have not tested getInitalLink yet). The PR by @odlund fixed it for me as well ❤️
@tvledesign You don't need to edit the code manually. You can also overwrite the firebase_dynamic_links_platform_interface dependency in your pubspec.yaml:
dependencies:
firebase_core: ^1.13.1
firebase_dynamic_links: ^4.1.0
flutter:
sdk: flutter
dependency_overrides:
firebase_dynamic_links_platform_interface:
git:
url: https://github.com/defiq-dev/flutterfire
ref: fix-type-cast-issue-in-dynamic-link-handling
path: packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface
I had the same problem with
onLink(Have not testedgetInitalLinkyet). The PR by @odlund fixed it for me as well ❤️@tvledesign You don't need to edit the code manually. You can also overwrite the
firebase_dynamic_links_platform_interfacedependency in yourpubspec.yaml:dependencies: firebase_core: ^1.13.1 firebase_dynamic_links: ^4.1.0 flutter: sdk: flutter dependency_overrides: firebase_dynamic_links_platform_interface: git: url: https://github.com/defiq-dev/flutterfire ref: fix-type-cast-issue-in-dynamic-link-handling path: packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface
Ah that's very good to know, thanks!
We had the same issue, pretty sure the PR above fixes it.
The PR from @odlund is working! Thank you 😃
is there any solution?
@CristCT Yes, use @odlund's PR (https://github.com/FirebaseExtended/flutterfire/pull/8263) with my instruction: https://github.com/FirebaseExtended/flutterfire/issues/8261#issuecomment-1065978390
Thanks for the detailed report and fix for this.
I guess since this PR adds utmParameters but utmParameters is Map<String, String>;
and linkData['utmParameters'] is <Object?, Object?> which is throwing below error for me:
Unhandled Exception: type '_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<String, String>'
The fix made by this PR : https://github.com/FirebaseExtended/flutterfire/pull/8263 fixes above.
/cc @russellwheatley @Salakar
dependencies: firebase_core: ^1.13.1 firebase_dynamic_links: ^4.1.0 flutter: sdk: flutter
dependency_overrides: firebase_dynamic_links_platform_interface: git: url: https://github.com/defiq-dev/flutterfire ref: fix-type-cast-issue-in-dynamic-link-handling path: packages/firebase_dynamic_links/firebase_dynamic_links_platform_interface
@nilsreichardt this works for android but not for ios can you please help me with that?
@Peeyush14198 For me, it's working for iOS and Android. I think in your case it's a different issue or you did the configuration for iOS wrong.
Same on iOs and Android. Not only with getInitialLink() but also with onLink.listen(). In FirebaseDynamicLinks.instance.onLink.listen(), the listen is never triggered.
same issue
@ahmarDebugger did you try to use @odlund's PR (#8263) with @nilsreichardt instructions?