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=123 与 dzm:///tabbar?id=123 前者就会被认为没有指定页面,后者不会出现问题,会进入到 /tabbar 页面。

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

相关推荐
陆断枫2 小时前
Flutter 3.47 动画引擎盘点:Impeller 全平台,和那些"新特性"
flutter
程序员老刘3 小时前
Flet 1.0 思路很好,可惜来晚了
flutter·ai编程·客户端
m0_738185829 小时前
Flutter 鸿蒙化实战:qr_code_scanner_plus 适配 OpenHarmony,二维码扫描
flutter·华为·harmonyos·鸿蒙
恋猫de小郭9 小时前
Flutter + EmbeddingGemma 2,谷歌发布完全端侧的 AI Edge Foresight
android·前端·flutter
君赏1 天前
基于 FlutterPatch 快速接入 Flutter 热更新
flutter
律宏阔1 天前
Dart FFI 内存管理:用 using + Arena 替代嵌套 try-finally
前端·flutter
律宏阔1 天前
Flutter 调用 Go:从 c-shared + ffigen 到 @Native + Native Assets 踩坑记录
前端·flutter
律宏阔1 天前
Dart FFI 回调无法使用局部变量?使用 NativeCallable.isolateLocal
前端·flutter
天空之城--1 天前
Android一周动态:AI编程、Compose与车载生态新信号
android·flutter
码林鼠1 天前
Flutter之Widget/State 入门文档
flutter