我有一个使用 goRoute 和底部导航栏的应用程序,并且在任何路线内我需要打开 ModalBottomSheet (在底部导航栏上)来显示一些数据。 这是我的 goRouter 实现的示例:
static final router = GoRouter(
initialLocation: homePath,
navigatorKey: rootNavKey,
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return MainScreen(
navigationShell: navigationShell,
);
},
branches: [
// home branch
StatefulShellBranch(navigatorKey: homeNavKey, routes: homeRoutes),
StatefulShellBranch(navigatorKey: otherNavKey, routes: Routes),
],
),
],);
static final otherRoutes = [
GoRoute(
path: otherMainPath,
pageBuilder: (context, state) {
return OtherPage();
},
routes: [
GoRoute(
path: otherDetailPath,
pageBuilder: (context, state) {
return OtherDetailPage();
}),
],
)];
现在,如果我从OtherDetailPage内部打开modalBottomSheet,如果我按下设备后退按钮,modalBottomSheet不会关闭,但应用程序会导航回OtherPage
这就是我打开 modalBottomSheet 的方式:
showModalBottomSheet(
isScrollControlled: true,
useRootNavigator: true,
context: context,
enableDrag: false,
builder: (context) {
return MyModalContent();
},
);
我希望该模式在后退按钮上关闭。我该如何修复它?
此问题在 github
上有问题