1、发现问题 Flutter 升级后发现报这个错误

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building IconTheme(color: Color(0xdd000000)):
flutter: A GlobalKey was used multiple times inside one widget's child list.
flutter: The offending GlobalKey was: [LabeledGlobalKey<NavigatorState>#3521f]
flutter: The parent of the widgets with that key was:
flutter:   IconTheme
flutter: The first child to get instantiated with that key became:
flutter:   Navigator-[LabeledGlobalKey<NavigatorState>#3521f]
flutter: The second child that was to be instantiated with that key was:
flutter:   IconTheme
flutter: A GlobalKey can only be specified on one widget at a time in the widget tree.
flutter:
flutter: The relevant error-causing widget was:

2、发现报错的地方指向 MaterialApp

 MaterialApp(
            title: 'XX商城',
            debugShowCheckedModeBanner: false,
            ...
            ...
            initialRoute: Routes.splashScreenPage,
          )

3、移除 initialRoute: Routes.splashScreenPage, 后问题解决

 MaterialApp(
            title: 'XX商城',
            debugShowCheckedModeBanner: false,
            ...
            ...
          )

4、项目启动的时候进入初始页面

 root 页面指向 splashScreenPage
 class Routes {
  static String root = "/";
 }

5、问题解决

Logo

一站式 AI 云服务平台

更多推荐