Flutter A GlobalKey was used multipletimes inside one widget'schild list.The ...

  • 安卓通过 scheme 调起未启动的 APP,进入 APP 后会白屏一会然后报错:

    A GlobalKey was used multipletimes inside one widget'schild list.The offending GlobalKey was:[LabeledGlobalKey<Navigatorstate>#7a685 Key Created bydefault]The parent of the widgets withthat key was:FocusInheritedscopeThe first child to getinstantiated with that keybecame:Navigator-[LabeledGlobalKey<NavigatorState>#7a685 KeyCreated by default]The second child that was tobe instantiated with that keywas :FocusInheritedScopeA GlobalKey can only bespecified on one widget at atime in the widget tree.See also: https://docs,flutter.dev/testing/

  • 原因就是使用的 initialRoute 没有配置完全导致的

    dart 复制代码
    /// MaterialApp
    Widget buildMaterialApp(BuildContext context) {
      return GetMaterialApp(
        title: '水哥自用框架',
        // ...更多配置
        // 这是正常的配置,指定初始路由
        initialRoute: widget.initialRoute,
        // 这是这是路由列表
        getPages: appRoutes.getPages,
        // 注意:就是这没有配置导致的,找不到路由的情况需要指定一个路由,可以设置为初始化的路由,也可以设置为找不到页面的路由
        // 配置好这个就不会报错了。
        unknownRoute: GetPage(name: appRoutes.initialRoute, page: () => widget.initialRoutePage),
      );
    }

    scheme 为什么会出现找不到路由?例如:dzm://?id=123dzm:///tabbar?id=123 前者就会被认为没有指定页面,后者不会出现问题,会进入到 /tabbar 页面。

    也可以通过强制给 scheme 解决问题,也可以通过配置好 unknownRoute 解决问题。

相关推荐
w_y_fan6 小时前
Flutter 滚动组件总结
前端·flutter
醉过才知酒浓6 小时前
Flutter Getx 的页面传参
flutter
火柴就是我1 天前
flutter 之真手势冲突处理
android·flutter
Speed1231 天前
`mockito` 的核心“打桩”规则
flutter·dart
法的空间1 天前
Flutter JsonToDart 支持 JsonSchema
android·flutter·ios
恋猫de小郭1 天前
Android 将强制应用使用主题图标,你怎么看?
android·前端·flutter
玲珑Felone1 天前
从flutter源码看其渲染机制
android·flutter
ALLIN2 天前
Flutter 三种方式实现页面切换后保持原页面状态
flutter
Dabei2 天前
Flutter 国际化
flutter