我正在try 添加一个动作扩展到我的Flutter应用程序.我打算使用动作发送一个图像到我的应用程序. Go Router用于路由在我的应用程序中,所以我必须使用Go Router进行深度链接. 由于我的应用程序的复杂性,我需要导航到嵌套路径.

一切看起来都是应该的,但我面临着一些意想不到的行为. 操作扩展或xcrun simctl openurl booted <url>命令打开应用程序,但没有导航正确的路径.redirect在从扩展或命令提示符打开时不调用.

这是我的路由配置

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(),
      ),
    ]),
  ],
);

下面是info.plist中的自定义URL方案部分

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

我try 了下面的命令来调用路由

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   

上面的命令都没有打开任何路径,除了主屏幕.

另外,我知道有this issue张唱片,但这个问题已经结束了,但我仍然无法弄清楚这项工作的变化或影响.

为了简化,我创建了一个示例应用程序,其行为如上所述.我希望你能告诉我,我的错误.

https://github.com/bahadirarslan/go_router_deeplink

推荐答案

您缺少info.plist的设置,无法启用Flutter Deep Linking.把这些添加到你的info.plist:

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

此外,图像捕获的路径不是您的示例中的image,而是image-capture.在进行上述更改后,以下各项确实起作用:

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

Flutter相关问答推荐

具有可变高度小部件的SingleChildScrollView内的列

允许冻结在初始化时使用工厂

为什么我的页面控制器在使用Riverpod时没有更改我的页面视图?

任务';:app:check DebugDuplicateClasss';的Ffltter Share_plus抛出执行失败

从.gitignore中排除.fvm/fvm_config.json

抖动问题:检测到0个或2个或更多具有相同值的[DropdownMenuItem]

谷歌 map 在 flutter 应用程序中显示错误的当前位置

参数类型void Function()无法分配给参数类型void Function(LongPressEndDetails)?

找不到任何与 com.google.firebase:firebase-sessions:[15.0.0, 16.0.0) 匹配的版本

Flutter:我应该使用哪种应用内购买服务?

「Flutter」错误:没有名为'kind'的命名参数

提供者、存储库和服务之间有什么区别?

减少 Flutter 中 API 的连接等待时间

在提供程序包更改通知程序中构建倒计时时钟

状况不佳 - Cubit

如何在 flutter 中创建渐变按钮

如何按值对列表中的 map 进行排序

.info/connected 这两个代码之间有什么区别吗?

Flutter - 异步文件读取异常处理

在 Flutter 中将提取的 Listview.builder 与两个列表一起使用