I am working on a Flutter app and would like to implement deep linking using custom URLs. However, I do not want to use the go_router package and prefer handling deep linking manually. What is the best method or approach to implement deep linking in a Flutter app with custom URL without relying on GoRoute?
Any suggestions or code examples would be highly appreciated.
2
Answers
You’re on the right track wanting to handle deep linking manually—it gives you a lot of flexibility! For implementing deep linking in Flutter without using the go_router package, you can make use of Navigator 2.0 combined with Uri parsing. The key steps are:
Set up the initial route handling by overriding the onGenerateRoute or using onGenerateInitialRoutes.
Use onGenerateRoute or onUnknownRoute to catch custom URL schemes and map them to your app’s routes.
Implement a RouteInformationParser to parse incoming URLs into a data structure your app can handle.
You can use the following library app_links.
To start with, you need to follow docs to configure Android / iOS and more here.
After, you just need to instanciate the plugin and subscribe to events like this:
For the
globalNavigatorKey
, you can assign it to yourMaterialApp
widget widget like this: