I am using the uni_links package together with the go_router in my app and my deep links are opening the app. I used this method to retrieve the deep link:
Future<void> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
final initialLink = await getInitialLink();
// Parse the link and warn the user, if it is not correct,
// ...
context.go('someLocation');
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
That is working perfectly fine on iOS. However on Android when opening a Deep Link, it automatically takes the link as a path
and go_router
tries to navigate to the location, which fails because the deep link is not an actual location. I am creating the location from the deep link, but there is also other information in that link so the link should not be the exact path.
It is also calling initUniLink
and going to the location (context.go(someLocation
) in the code above is called. But simultaneously go_router fails and the errorBuilder
is triggered, since the path didn't match any location.
What am I doing wrong here? Why is Android using the link as path right away? How can I avoid that?
My only idea was to catch the link inside the routers redirect
and check if it is a deep link. If so, I could simply navigate the user to the HomeView. And initUniLink
will work anyway. But that feels wrong, since go_router
shouldn't even be called to push to the location from the deep link.
Any idea? Happy for every help. Let me know if you need any more info!
** Configure Deep Links in AndroidManifest.xml:
Evaluate go_router Necessity: Assess whether go_router causes conflicts with Android deep link handling. Consider using default Flutter navigation if go_router is not essential.
Custom Redirect Handling in go_router: