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

相关推荐
SoaringHeart1 天前
Flutter进阶:OverlayEntry 插入图层管理器 NOverlayZIndexManager
前端·flutter
程序员老刘1 天前
Flutter 3.44 有哪些变化?(官方blog完整翻译)
flutter·ai编程·客户端
山屿落星辰1 天前
Flutter 企业级架构设计实战:Clean Architecture + 分层模块化 + 依赖注入全解析
flutter
山屿落星辰1 天前
Flutter 高级特性实战:动画、自定义绘制、平台通道与 Web 优化
前端·flutter
程序软件分享1 天前
2026旗舰版 Java+Flutter 期货微交易系统源码全开源多语言平台
flutter·交易所源码·微盘源码·微交易源码
飞龙14775657467501 天前
Flutter 安全存储插件全面解析:从入门到进阶
flutter
带带弟弟学爬虫__1 天前
dyAPP数据采集-个人主页、发布、搜索、评论
服务器·python·算法·flutter·java-ee·django
icc_tips1 天前
Flutter runAppAsync() 详解:干净的异步应用启动
前端·flutter
恋猫de小郭1 天前
Android 发布全新性能分析器,实用性和性能大升级
android·前端·flutter
恋猫de小郭2 天前
Flutter 3.44 发布啦,超级大版本更新!!!
android·flutter·ios