flutter GoRouter:按下后关闭 ModalBottomsheet

问题描述 投票:0回答:1

我有一个使用 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();
  },
);

我希望该模式在后退按钮上关闭。我该如何修复它?

flutter flutter-go-router flutter-showmodalbottomsheet
1个回答
0
投票

此问题在 github

上有问题
  1. 简单的解决方案,降级到 v12
  2. 尝试使用代码解决方法 enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.