Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android deep link #1906

Open
hanumanjiblog opened this issue Oct 7, 2021 · 15 comments
Open

Android deep link #1906

hanumanjiblog opened this issue Oct 7, 2021 · 15 comments
Assignees

Comments

@hanumanjiblog
Copy link

Of user click a link then app will open and open particular page using get navigator, how is this possible with get navigator.
deep linking on Android

@alejandrogiubel
Copy link

Same here

@diego-lipinski-de-castro

any updates?

@iSWATxJOKERi
Copy link

Any updates on this? Is it possible/has someone done Android deep linking following the flutter docs and using getmaterialapp / get navigation? or even using the uni_links package? @jonataslaw I know you're busy with getx 5, do you have any reccomendations?

@iSWATxJOKERi
Copy link

@hanumanjiblog @alejandrogiubel @diego-lipinski-de-castro were any of you able to figure out? and willing to share

@wantroba
Copy link

wantroba commented Nov 17, 2023

I have the following situation happening here:

I followed the deeplink settings for Android and iOs that are described here (except the GoRouter part because I'm using Get):

https://docs.flutter.dev/cookbook/navigation/set-up-app-links
https://docs.flutter.dev/cookbook/navigation/set-up-universal-links

The following code works:

return GetMaterialApp(
.....
initialRoute: "/",
routes: {
"/privacy": (context) => const PolicyPrivacyPage(),
"/terms": (context) => const TermsPage(),
"/support" : (context) => const SupportPage(),
"/download" : (context) => const DownloadPage(),
},
getPages: [
GetPage(name: "/", page: () => const HomePage()),
GetPage(name: "/privacy", page: () => const PolicyPrivacyPage()),
GetPage(name: "/terms", page: () => const TermsPage()),
GetPage(name: "/support", page: () => const SupportPage()),
GetPage(name: "/download", page: () => const DownloadPage()),
GetPage(
name: '/report',
page: () {
String? reportId = Get.parameters["id"];
if(reportId!=null) {
return LoadReportPage(reportId);
}else{
return const HomePage();
}
),

),
],
);

In this case, the links must be in the format: www.example.com/report?id=1234


But I need the app to open links in the format www.example.com/report/1234
so i tried the following code according to the Get documentation:

GetPage(
name: '/report/:id',
page: () {
String? reportId = Get.parameters["id"];
if(reportId!=null) {
return LoadReportPage(reportId);
}else{
return const HomePage();
}
),

But then I'm getting the error above:

The following _TypeError was thrown building _FocusInheritedScope:
Null check operator used on a null value

The relevant error-causing widget was:
Directionality Directionality:file:///C:/Users/wantr/AppData/Local/Pub/Cache/hosted/pub.dev/get-4.6.6/lib/get_navigation/src/root/get_material_app.dart:328:12
When the exception was thrown, this was the stack:
#0 ParseRouteTree._parseParams (package:get/get_navigation/src/root/parse_route.dart:173:55)
#1 ParseRouteTree.matchRoute (package:get/get_navigation/src/root/parse_route.dart:64:28)
#2 PageRedirect.needRecheck (package:get/get_navigation/src/routes/route_middleware.dart:258:33)
#3 PageRedirect.page (package:get/get_navigation/src/routes/route_middleware.dart:199:12)
#4 GetMaterialApp.initialRoutesGenerate (package:get/get_navigation/src/root/get_material_app.dart:348:9)
#5 _WidgetsAppState.build. (package:flutter/src/widgets/app.dart:1641:53)
#6 NavigatorState.restoreState (package:flutter/src/widgets/navigator.dart:3419:41)
#7 RestorationMixin._doRestore (package:flutter/src/widgets/restoration.dart:923:5)
#8 RestorationMixin.didChangeDependencies (package:flutter/src/widgets/restoration.dart:909:7)
#9 NavigatorState.didChangeDependencies (package:flutter/src/widgets/navigator.dart:3466:11)
#10 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5448:11)
#11 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5273:5)
... Normal element mounting (405 frames)
#416 _InheritedProviderScopeElement.mount (package:provider/src/inherited_provider.dart:411:11)
... Normal element mounting (7 frames)
#423 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#430 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (7 frames)
#437 _NestedHookElement.mount (package:nested/nested.dart:187:11)
... Normal element mounting (7 frames)
#444 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:222:11)
... Normal element mounting (27 frames)
#471 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4182:16)
#472 Element.updateChild (package:flutter/src/widgets/framework.dart:3707:18)
#473 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1253:16)
#474 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1222:5)
#475 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:1169:18)
#476 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2719:19)
#477 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1168:13)
#478 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:1001:7)
#479 WidgetsBinding.scheduleAttachRootWidget. (package:flutter/src/widgets/binding.dart:981:7)
#483 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 3 frames from class _Timer and dart:async-patch)

The following assertion was thrown building _FocusInheritedScope:
A GlobalKey was used multiple times inside one widget's child list.

The offending GlobalKey was: [LabeledGlobalKey#23677 Key Created by default]
The parent of the widgets with that key was: _FocusInheritedScope
The first child to get instantiated with that key became: Navigator-[LabeledGlobalKey#23677 Key Created by default]
dirty
dependencies: [UnmanagedRestorationScope]
state: NavigatorState#48c2d(lifecycle state: initialized)
The second child that was to be instantiated with that key was: _FocusInheritedScope
A GlobalKey can only be specified on one widget at a time in the widget tree.
The relevant error-causing widget was:
Directionality Directionality:file:///C:/Users/wantr/AppData/Local/Pub/Cache/hosted/pub.dev/get-4.6.6/lib/get_navigation/src/root/get_material_app.dart:328:12
When the exception was thrown, this was the stack:
#0 Element._retakeInactiveElement. (package:flutter/src/widgets/framework.dart:4103:11)
#1 Element._retakeInactiveElement (package:flutter/src/widgets/framework.dart:4117:8)
#2 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4164:35)
#3 Element.updateChild (package:flutter/src/widgets/framework.dart:3701:20)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#5 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#6 ProxyElement.update (package:flutter/src/widgets/framework.dart:5628:5)
#7 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:107:11)
#8 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#9 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6441:14)
#10 Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#12 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5462:11)
#13 Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#14 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
#15 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
#16 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#17 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#18 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#19 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:952:7)
#23 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 3 frames from class _Timer and dart:async-patch)

Am i doing something wrong? Is there a way to open links in www.example.com/report/1234 format?

@wantroba
Copy link

I don't know if i can help with something but i edited the code in the file parse_route.dart to print some stuffs:

Map<String, String> _parseParams(String path, PathDecoded routePath) { final params = <String, String>{}; var idx = path.indexOf('?'); if (idx > -1) { path = path.substring(0, idx); final uri = Uri.tryParse(path); if (uri != null) { params.addAll(uri.queryParameters); } } var paramsMatch = routePath.regex.firstMatch(path); print(">>>>>>>>>>> path ${path}"); print(">>>>>>>>>>> routePath.regex ${routePath.regex}"); print(">>>>>>>>>>> routePath.keys ${routePath.keys}"); print(">>>>>>>>>>> paramsMatch ${paramsMatch}"); for (var i = 0; i < routePath.keys.length; i++) { var param = Uri.decodeQueryComponent(paramsMatch![i + 1]!); params[routePath.keys[i]!] = param; } return params; }

The Web output:

>>>>>>>>>>> path /report/KfcegKeUB6KrfJvo4akA
>>>>>>>>>>> routePath.regex RegExp/^/report/(?:([\w%+-._~!$&'()*,;=:@]+))/?$/
>>>>>>>>>>> routePath.keys [id]
>>>>>>>>>>> paramsMatch Instance of '_MatchImplementation'

The Android output:

I/flutter (14536): >>>>>>>>>>> path https://example.com.br/report/KfcegKeUB6KrfJvo4akA
I/flutter (14536): >>>>>>>>>>> routePath.regex RegExp: pattern=^/report/(?:([\w%+-._~!$&'()*,;=:@]+))/?$ flags=
I/flutter (14536): >>>>>>>>>>> routePath.keys [id]
I/flutter (14536): >>>>>>>>>>> **paramsMatch null**

It only works on web

@mdabusaif
Copy link

@wantroba. I am also getting the exact same issue. Have you found any workaround yet?

@wantroba
Copy link

@wantroba. I am also getting the exact same issue. Have you found any workaround yet?

The only way that worked for me was to use the links in the format www.example.com/page?id=1234.

@mdabusaif
Copy link

Thanks. This workaround gives a good go for me.

@LidiiaPl
Copy link

What if the link cannot be changed? Are there some other ways to make it work?

@mdabusaif
Copy link

What if the link cannot be changed? Are there some other ways to make it work?

With Getx current version(4.6.6) path variable is not going to work. You have to wait for an update of Getx(Probably 5.0.0). Or you can use other routing system(like goRoute) if you wish to not using getx's named route.

@SundayPSM
Copy link

When i am using Getx and uni_links I am getting an Error on LabledGlobelKey. Need Help. Thanks in advance
App Opened Normally (Icon Tap) Working
App in Background and Link Tap Working
App Terminated, Opened Normally then it is working
App Terminated, Opened Tapping Link then it is not working. Then it is giving error.

@korutx
Copy link
Contributor

korutx commented Mar 29, 2024

I've submitted a PR (#3067) that aims to address the problem you've encountered.

@xelent-nabeel
Copy link

xelent-nabeel commented Apr 25, 2024

have someone resloved this issue

When i am using Getx I am getting an Error on LabledGlobelKey. Need Help. Thanks in advance i can't used any package just like uni_link because getx handle it byself
App Opened Normally (Icon Tap) Working
App in Background and Link Tap Working
App Terminated, Opened Normally then it is working
App Terminated, Opened Tapping Link then it is not working. Then it is giving error.

@SergeyYaniuk
Copy link

@xelent-nabeel Probably you already fixed issue, but for others I resolved this with changing initialRoute path from '/home' to just '/' and now it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests