PersistentBottomNavBar
PersistentBottomNavBar copied to clipboard
How to pop with withNavBar true?
I tried to push withNavBar:false
.
pushNewScreen(context, withNavBar: false, screen: LoginPage());
But when I pop: Navigator.of(context).pop();
The nav bar won't appear. So how should I pop withNavBar:true?
I experienced this problem as well.
Me Too.
Which flutter version do you use?
Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision f4abaa0735 (8 weeks ago) • 2021-07-01 12:46:11 -0700 Engine • revision 241c87ad80 Tools • Dart 2.13.4
Hi, is there any solution for this case? I have the same case like @y0unghe's
I solve this problem by creating a double context. PersistentBottomNavBar Context and Navigator Context.
Create a singleton class named App, that have 2 properti
class App {
static GlobalKey<NavigatorState> navigator = GlobalKey();
static BuildContext context = navigator.currentContext!;
}
So the App class has a navigator key which has a context and assigned in MaterialApp in main.dart
. And dont forget to reassigned App.context
in PersistentTabView.selectedTabScreenContext()
method to update the context of the current page.
MaterialApp(navigatorKey: App.navigator),
PersistentTabView(
selectedTabScreenContext: (context) {
if (context != null) {
App.context = context;
}
},
)
And then we if pop from withNav: false
send context in current widget Navigator.pop(context)
and withNav: true
send App.context Navigator.pop(App.context)
.
Hope this help.