flutterflutter-go-routerflutter-deep-link

Flutter Go Router Deep Linking Not Working As Expected


I am trying to add an action extension to my Flutter app. I intend to use action to send an image to my app. Go Router was used for routing in my app, so I have to use Go Router for deep links. Due to the complexity of my app, I need to navigate to a nested route.

Everything looks as it should be but I face some unexpected behaviours. Either Action extension or xcrun simctl openurl booted <url> command opens the app but not navigating the correct path. Also redirect not invoking while opening from extension or command prompt.

Here is my route config

final _router = GoRouter(
  redirect: (context, state) {
    print(state);
    return null;
  },
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const MyHomePage(),
    ),
    GoRoute(path: '/first', builder: (context, state) => const FirstScreen(), routes: [
      GoRoute(
        path: 'image-capture',
        builder: (context, state) => const ImageDart(),
      ),
    ]),
  ],
);

Here is the custom url scheme part from info.plist

 <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>com.bahadirarslan.goRouterDeeplink</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>gorouterapp</string>
            </array>
        </dict>
    </array>

I tried the commands below to invoke routing

xcrun simctl openurl booted gorouterapp://com.bahadirarslan.goRouterDeeplink/first
xcrun simctl openurl booted gorouterapp://com.bahadirarslan.goRouterDeeplink/first/image
xcrun simctl openurl booted gorouterapp://first/image       
xcrun simctl openurl booted gorouterapp://a/first/image
xcrun simctl openurl booted gorouterapp:/first/image   

Neither of the commands above opened any route except the home screen.

Also, I am aware of this issue record but the issue was closed as done but I still couldn't figure out the change or effect of this work.

To simplify, I created an example app that behaves as described above. I hope you can show me, my mistake.

https://github.com/bahadirarslan/go_router_deeplink


Solution

  • You are missing a setting from info.plist to enable Flutter Deep Linking. Add these to your info.plist:

    <key>FlutterDeepLinkingEnabled</key>
    <true/>
    

    Also, the path for the image capture is not image as in your example, but image-capture. After the above change, these do work:

    xcrun simctl openurl booted gorouterapp://com.bahadirarslan.goRouterDeeplink/first
    xcrun simctl openurl booted gorouterapp://com.bahadirarslan.goRouterDeeplink/first/image-capture