PersistentBottomNavBar icon indicating copy to clipboard operation
PersistentBottomNavBar copied to clipboard

How to pop with withNavBar true?

Open y0unghe opened this issue 3 years ago • 6 comments

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?

y0unghe avatar Aug 18 '21 03:08 y0unghe

I experienced this problem as well.

ArthitNam avatar Aug 19 '21 03:08 ArthitNam

Me Too.

abhimanyu95 avatar Aug 20 '21 11:08 abhimanyu95

Which flutter version do you use?

PcolBP avatar Aug 24 '21 06:08 PcolBP

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

abhimanyu95 avatar Aug 24 '21 06:08 abhimanyu95

Hi, is there any solution for this case? I have the same case like @y0unghe's

wahyu-handayani avatar Jan 06 '22 01:01 wahyu-handayani

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.

zalviandyr avatar Dec 10 '22 08:12 zalviandyr