我有两个嵌套的路由:
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_screen
和coffee_details_screen
的pageBuilder
都被调用:
CoffeeDetailsScreen.routeName,
extra: CoffeeDetailsScreenArgs(productId: product.id),
);
型
- 如果我现在在
coffee_details_screen
中,我打开flutter devtools并按下select widget,并且我还在menu_screen
和coffee_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}',
);
型
为什么会发生这种情况,是我使用路由器时的错误还是什么问题?
1条答案
按热度按时间bxpogfeg1#
原来是库本身的一个bug。所以一旦维护人员在软件包中修复它,它就会得到解决。https://github.com/flutter/flutter/issues/125900