Flutter: CupertinoTabBar does not disappear when moving to the next screen - flutter

I'm running the Flutter Gallery example from Google:
https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/cupertino/cupertino_navigation_demo.dart
In the gif below, notice how when I navigate from one screen to the next, the Cupertino Tab Bar stays at the bottom of the screen.
The reason why this is the case is that it is a widget that lays within the parent widget CupertinoNavigationDemo and while the tabs are swapped in and out of the view, the tab bar remains.
Is there a way to get rid of the Tab Bar when navigating?

set rootNavigator: true
Navigator.of(context, rootNavigator: true).push(MaterialPageRoute(
builder: (context) => "your new routes",
));

Related

Flutter: Update of status bar color inconsistent with update of other widgets of screen

I followed this page to change status bar color for different screens in flutter.
As per the above link, to change the status bar color for each screen we should update it before navigating to next screen but this is showing a delay in loading of other widgets as compared to status bar color update. Attaching gif below for reference.
// Before navigating back to home screen, updating the color of status bar.
WillPopScope(
onWillPop: () async {
changeStatusBarColor(Colors.blue);
return true;
},
child: Scaffold(
.....
))
Is there any other way to update status bar color such that it reflects its update with other widgets on screen ?
[Gif: This may seem a little fast here but its very much noticeable in actual device]
You can do an override, but this will update the entire app with this new colour. Not Sure thats what you want.

How to hide bottom tab navigator (persistent_bottom_nav_bar) when the screen is not the main screens-Flutter

I am currently using persistent_bottom_nav_bar: ^4.0.2 package of flutter which showing 3 screens (A,B,C screens) in the bottom tab navigator. In the first screen I have a button that navigate user to another screen (D screen). The problem is the bottom tab navigator (persistent_bottom_nav_bar) is still showing in D screen, while the main screens are AB,C. Is there a way to hide persistent_bottom_nav_bar when the screen is not one of three main screen ?
can you check persistent_bottom_nav_bar in example code.
onScreenHideButtonPressed: () {
setState(() {
_hideNavBar = !_hideNavBar;
});
},
I think there is a nice feature that comes with the plugin itself (check out the documentation on pub.dev here https://pub.dev/packages/persistent_bottom_nav_bar, it's allowed you to navigate to a new screen without the navbar and when you pop back the navbar will show
try this
PersistentNavBarNavigator.sepushNewScreen();
there are some parameters that are required "screen & context" which is the screen you want to navigate to.
the parameter "withNavBar" it's a bool (optional) when you pass false the navbar will not show on the new screen!
you could try this after importing
PersistentNavBarNavigator.pushNewScreen(
context,
screen: newScreen(),
withNavBar: false,
);

Flutter navigation back to home screen

I have a flutter app that has the following drawer:
Routes:
Home: "/"
Nearby: "/nearby"
Applied: "/applied"
The behaviour I want to achieve is when the user clicks the android back button from nearby and applied screens, the app should take them to the home screen. If they press the back button from the home screen again it takes them out of the app.
Just to clarify here if they go to nearby, then to applied then click the back button it should take them to home, not applied.
Here is my code for navigating when nearby and applied drawer items are selected:
Navigator.pushNamedAndRemoveUntil(
context,
routeName,
ModalRoute.withName("/")
);
I expected this to leave the following routes in the stack:
home
selected page
But what I am getting is from nearby or applied screen when I tap the back button on android it takes me out of the app, rather than drop me to the home screen.
What am I missing? How can I achieve the behaviour I'm looking for?
Note that I know there's a solution using WillPopScope widget but I am looking for a solution that uses the navigation stack. More importantly I'm interested to know why the above scenario is not working.
Navigator.of(context).popUntil((route) => route.isFirst);
Add this WllPopCallBack() in NearBy and Apply widgets.
Future<bool> _willPopCallback() async {
Navigator.pushNamedAndRemoveUntil(
context,
routeName,
ModalRoute.withName("/")
);
return false; // return true if the route to be popped
}
Add this WllPopScope widget over Scaffold() in NearBy and Apply widgets like this:
new WillPopScope(child: new Scaffold(), onWillPop: _willPopCallback)

Flutter launch new independent screen

I am having trouble launching new screen widget. I have main.dart where I am using bottomNavigationBar and body for ViewPager UI. Now I have 3 bottom tabs and when I go to 2nd tab's view and click on a button to launch another screen/view using:
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ViewMyContactList(),
),
)
the new screen replaces the 2nd tab's view, when I go to 3rd tab then come back to 2nd tab, the new screen is gone and 2nd tab's initial screen is back. Also when new screen replaces the 2nd screen's initial view and when I do system back press in Android, the app exits straightaway.
You are trying to do Multiple Navigators with BottomNavigationBar
You can reference this doc for detail https://medium.com/coding-with-flutter/flutter-case-study-multiple-navigators-with-bottomnavigationbar-90eb6caa6dbf
Each tab must keep it'own Page Route, you can use the demo code in doc or
You can use the following two package to help you
https://pub.dev/packages/multi_navigator_bottom_bar
Helps you to build multi-navigator bottom navigation bar more easily.
https://pub.dev/packages/nested_navigators Flutter widget for implementing multiple nested navigators with their own route stacks.

how to route to a new page without the Cupertino bottom bar

I am using the Cupertino tab to display a bottom navigation bar and it working good. Now, I want to route to a new page from one of the tab pages (E.g login)and not have the bottom navigation. I tried the code below and I still see the bottom navigation.
How can I route to a page and not show the bottom navigation
Navigator.push(
context,
CupertinoPageRoute<void>(
title: "login",
builder: (BuildContext context) => LoginScreen(),
),
);
The static methods on Navigator, like Navigator.push or Navigator.of use the nearest enclosing Navigator of the context argument. When using a CupertinoTabScaffold, every tab has a nested Navigator to provide in-tab navigation, as is the default iOS behavior. You can get the root Navigator using Navigator.of(context, rootNavigator: true) and push your route on that:
Navigator.of(context, rootNavigator: true).push(route)
More info about navigators in the docs