skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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:

    final appLinks = AppLinks();
    
    final sub = appLinks.uriLinkStream.listen((uri) {
        if (uri.path == 'your/path') {
          Navigator.pushNamed(
            globalNavigatorKey.currentContext!,
            '/your/flutter/page',
        );
        }
    });
    

    For the globalNavigatorKey, you can assign it to your MaterialApp widget widget like this:

    final GlobalKey<NavigatorState> globalNavigatorKey =
        GlobalKey<NavigatorState>();
    
    // [...]
    
    MaterialApp(
      navigatorKey: globalNavigatorKey,
      // ...
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search