I am new to flutter, I have a login screen, on clicking signIn button I pushed a route(Landing Screen) using pushReplacement (beacause i don't want to let the user hit back button and go to login screen again), my landing page consist of bottomNavigationBar, i want my bottomNavigtionBar persist all the time in app so i decided to use persistent_bottom_nav_bar libaray.
my navbar items are (home, serach and setting), on my home navBarItem child widget i have one button named "goToNextScreen", when i pressed "goToNextScreen" button i pushed a new route, now on this next Screen i just want to have a back button on appbar so that i can come back to my home navbarItem child widget again(Landing Screen).
Asked
Active
Viewed 202 times
0

paras
- 109
- 3
- 7
2 Answers
0
To add a back button to AppBar you have to define the leading property
a little example of it
AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
bottomOpacity: 0,
shadowColor: Colors.transparent,
leading: IconButton(
icon: SvgPicture.asset(
"assets/icons/arrow_back.svg",
color: AppColors.currentAppTheme.boxBackgroundTextColor,
),
onPressed: () {
Navigator.pop(context);
},
),
);

Patrick G.
- 458
- 5
- 7
-
AppBar is common for both screens. I have added my NextScreen Image also for better understanding. – paras Aug 14 '21 at 21:41
-
You can define your AppBar global to your app then access it from any page you want. You can create a class that extends or wrap AppBar then add custom property like "showBackButton" then in the build method you can check for the property and decide what to do.. – Patrick G. Aug 16 '21 at 07:45
0
Inside goToNextScreen
are you using Navigator.pushReplacement
?
If yes, change it to Navigator.push
.
Navigator.pushReplacement
removes the current screen from the stack before navigating to next screen.
Since you have only one screen left and that too is replaced by the NextScreen
, you have no-where to go back.

Raj Yadav
- 9,677
- 6
- 35
- 30
-
I used Navigator.push. I used Navigator.pushReplacement when i navigate from login screen to landing screen that's why on my landing screen back button is not appeard and when i click on "goToNextScreen" button i use Navigator.push to navigate to my NextScreen, also same appbar is shared with my NextScreen. – paras Aug 14 '21 at 21:47
-
Share your code! In case both the screens are sharing same container and thus the same appBar, then you need to check for the changed value and add back button on your own and write a special logic to navigate up. – Raj Yadav Aug 14 '21 at 22:08