Reputation: 550
I'm using bottom navigation bar, and I need to push a view with bottom nav bar to be persistent.
And this is the main page:
MaterialApp(
theme: ThemeData(
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
})),
home: Scaffold(
body: IndexedStack(
index: _pageIndex,
children: const <Widget>[
HomeView(),
VideosSectionsView(),
FavoritesView()
],
),
bottomNavigationBar: Column(
mainAxisSize: MainAxisSize.min,
children: [
showBottomPlayer ? bottomPlayer(context) : Row(),
const SizedBox(height: 0),
bottomNavigationBar()
],
)));
The problem is, when I push a view from HomeView to SecondView, and push again to ThirdView, the swipe back gesture from the ThirdView (in left edge of the screen) send me back to HomeView, but I want it to send me to SecondView (so popping only one view, not all the stack) do you know to achieve this?
For that I use CupertinoPageRoute:
Navigator.of(context, rootNavigator: false).push(
CupertinoPageRoute<bool>(
fullscreenDialog: false,
builder: (BuildContext context) => SecondView()
)
);
This is weird because if I set "rootNavigator" to true, it's working and I can pop only the last view of the stack, but the bottom nav bar is not persisted anymore in navigation !
So I have to chose between a good swipe back gesture or persisted nav bar ...
There's no problem with getting back programmatically :
Navigator.of(context).pop(true);
So I want the same thing with Swipe Gesture, thanks all
Upvotes: 1
Views: 1587
Reputation: 390
you can use pageView https://api.flutter.dev/flutter/widgets/PageView-class.html. This is the example https://medium.com/flutter-community/a-deep-dive-into-pageview-in-flutter-with-custom-transitions-581d9ea6dded
Upvotes: 0