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

相关推荐
晚烛1 天前
实战前瞻:构建高可靠、低延迟的 Flutter + OpenHarmony 智慧交通出行平台
前端·javascript·flutter
ujainu小1 天前
Flutter 权限管理实战手册:permission_handler 全平台适配与最佳实践
flutter
子榆.1 天前
Flutter 与开源鸿蒙(OpenHarmony)工程化实践:CI/CD、性能监控与多端发布
flutter·开源·harmonyos
QuantumLeap丶1 天前
《Flutter全栈开发实战指南:从零到高级》- 26 -持续集成与部署
android·flutter·ios
晚烛1 天前
实战前瞻:构建高安全、强协同的 Flutter + OpenHarmony 智慧金融移动银行平台(支持国产密码体系、生物认证与信创全栈适配)
安全·flutter·金融
子榆.1 天前
Flutter 与开源鸿蒙(OpenHarmony)国际化与无障碍适配指南:打造真正包容的跨平台应用
flutter·华为·开源·harmonyos
子榆.1 天前
Flutter 与开源鸿蒙(OpenHarmony)深度集成:从原理到实战进阶
flutter·华为·开源·harmonyos
子榆.1 天前
Flutter 与开源鸿蒙(OpenHarmony)的融合:跨平台开发新纪元
flutter·华为·开源·harmonyos
走在路上的菜鸟1 天前
Android学Dart学习笔记第二十三节 类-扩展类型
android·笔记·学习·flutter
晚烛1 天前
智启工厂脉搏:基于 OpenHarmony + Flutter 的信创工业边缘智能平台构建实践
前端·javascript·flutter