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 解决问题。

相关推荐
2501_938963961 小时前
Flutter 3.19 桌面应用开发:适配 Windows/macOS 端窗口大小与菜单栏自定义
windows·flutter·macos
星释1 小时前
鸿蒙Flutter三方库适配指南:07.插件开发
flutter·华为·harmonyos
SoaringHeart15 小时前
Flutter疑难解决:单独让某个页面的电池栏标签颜色改变
前端·flutter
西西学代码16 小时前
Flutter---个人信息(3)---实现修改性别
flutter
西西学代码17 小时前
Flutter---ListTile列表项组件
flutter
西西学代码18 小时前
Flutter---个人信息(1)---实现简单的UI
开发语言·javascript·flutter
程序员老刘20 小时前
Dart宏被砍掉的真相:为什么Go、Python、Java等高级语言都拒绝宏?
flutter·编程语言·dart
月伤591 天前
Flutter中的Text换行问题
flutter
东哥很忙XH1 天前
flutter开发的音乐搜索app
android·javascript·flutter
默默_david1 天前
在Flutter中使用信号量解决异步冲突
flutter·dart