I have an app that use goRoute with bottomNavigation bar, and inside any routes i need to open a ModalBottomSheet (over bottomNavBar) for show some data.
Here it is an example of my goRouter implementation:
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();
}),
],
)];
Now, if i open a modalBottomSheet from inside OtherDetailPage, if i press device back button modalBottomSheet does not close, but app navigates back to OtherPage
This is how i open modalBottomSheet:
showModalBottomSheet(
isScrollControlled: true,
useRootNavigator: true,
context: context,
enableDrag: false,
builder: (context) {
return MyModalContent();
},
);
I want that modal closes on back button. How can i fix it?