ios 当我在flutter inspector中按下“Select Widget”时,GoRouter将错误的参数传递到路由

h4cxqtbf  于 12个月前  发布在  iOS
关注(0)|答案(1)|浏览(110)

我有两个嵌套的路由:

GoRoute(
            parentNavigatorKey: _homePageShellNavigatorKey,
            name: MenuScreen.routeName,
            path: '/menu_screen',
            pageBuilder: (_, state) {
              assert(
                state.extra is MenuScreenArgs || state.extra == null,
                'extra of menu_screen route should be null or have a type of MenuScreenArgs,'
                ' but instead got ${state.extra.runtimeType}',
              );
              return MaterialPage(
                child: MenuScreen(
                  args: state.extra as MenuScreenArgs?,
                ),
              );
            },
            routes: [
              GoRoute(
                parentNavigatorKey: _rootNavigatorKey,
                name: CoffeeDetailsScreen.routeName,
                path: 'coffee_details_screen',
                pageBuilder: (_, state) {
                  assert(
                    state.extra != null &&
                        state.extra is CoffeeDetailsScreenArgs,
                    'extra of coffee_details_screen route should have a type of'
                    ' CoffeeDetailsScreenArgs,'
                    ' but instead got ${state.extra.runtimeType}',
                  );
                  return MaterialPage(
                    child: CoffeeDetailsScreen(
                      args: state.extra as CoffeeDetailsScreenArgs,
                    ),
                  );
                },
              ),
              GoRoute(
               // ... another nested route
              ),
            ],
          ),

字符串

  • 如果我在,比如说主屏幕,并转到menu_screen,那么menu_screen路由的页面构建器被调用,Assert通过,没有错误
  • 如果我在menu_screen中调用这段代码,那么coffee_details_screen被成功推送,但是menu_screencoffee_details_screenpageBuilder都被调用:
CoffeeDetailsScreen.routeName,
                extra: CoffeeDetailsScreenArgs(productId: product.id),
              );

  • 如果我现在在coffee_details_screen中,我打开flutter devtools并按下select widget,并且我还在menu_screencoffee_details_screen的'pageBuilder'上放置断点,那么我注意到它们都被调用了,但是当menu_screen builder被调用时,它被传递了错误的args,它被传递了coffee_details_screen的args,这使得Assert失败:
assert(
                state.extra is MenuScreenArgs || state.extra == null,
                'extra of menu_screen route should be null or have a type of MenuScreenArgs,'
                ' but instead got ${state.extra.runtimeType}',
              );


为什么会发生这种情况,是我使用路由器时的错误还是什么问题?

bxpogfeg

bxpogfeg1#

原来是库本身的一个bug。所以一旦维护人员在软件包中修复它,它就会得到解决。https://github.com/flutter/flutter/issues/125900

相关问题