persistent_bottom_nav_bar in flutter disappear - flutter

I'm using persistent_bottom_nav_bar package and when I navigate to anew screen from an alertdialog the navigation bar disappears even when I use
'''
PersistentNavBarNavigator.pushNewScreen(
context,
screen: doseForm(
medName: medName,
)
withNavBar: true, // OPTIONAL VALUE. True by default.
pageTransitionAnimation: PageTransitionAnimation.cupertino,
);
'''

Related

Navigate new Screen with persist nav bar

from cart page i Navigate login page without persist nav page, its okey.
PersistentNavBarNavigator.pushNewScreen(
context,
screen: Login(),
withNavBar: false, // OPTIONAL VALUE. True by default.
pageTransitionAnimation: PageTransitionAnimation.cupertino,
);
but when login success i want navigate next page from cart page with persist nav bar
PersistentNavBarNavigator.pushNewScreen(
context,
screen: Nexpage(),
withNavBar: true, // OPTIONAL VALUE. True by default.
pageTransitionAnimation: PageTransitionAnimation.cupertino,
);
but its doesnot work

How do I verify an alert dialog has appeared using mockingjay in a widget test?

Using the mockingjay Flutter package, how do I verify in a widget test that an alert dialog has been displayed after e.g. tapping a button? The alert dialog is displayed using the showDialog function.
This is very similar to verifying page navigation behaviour, the thing that caught me out was the showDialog function must have the parameter useRootNavigator set to false, as documented in the example project. Without it the test will fail to detect that the alert dialog was displayed.
showDialog(
context: context,
useRootNavigator: false, // By default this is true, which won't work with Mockingjay
routeSettings: RouteSettings(name: 'verify_checkout_failure'),
builder: (context) {
return AlertDialog(title: Text('Checkout failed'));
});
Then in your test:
await tester.tap(find.byType(PlaceOrderButton));
verify(
() => mockNavigator.push(
any(
that: isRoute<void>(
whereName: equals('verify_checkout_failure'),
),
),
),
);

how to make showModalBottomSheet background become pressable

just like the title says, when the showModalBottomSheet appear i want to press some button in the body/screen without closing the showModalBottomSheet i already set
isDismissible: false,
barrierColor: Colors.transparent,
but no button can be press
The short answer to your question is to wrap your bottom sheet with a GestureDetector and to do some processing in there yourself and avoid the touch event to get to the modal sheet. Here is a link to a similar answer on SO.
From what I understand, ModalBottomSheet internally uses BottomSheet and its code, where the actual presentation is done looks like this:
return AnimatedBuilder(
animation: widget.route!.animation!,
child: BottomSheet(
animationController: widget.route!._animationController,
onClosing: () {
if (widget.route!.isCurrent) {
Navigator.pop(context);
}
},
If you look at the onClosing() callback, it simply dismisses the object without checking with any external callbacks so I don't really think you can achieve that with a modal bottom sheet in Flutter without wrapping it inside a GestureDetector

How can i make shared appBar and bottomNavigation across flutter screens

i am new to flutter and i would like to have a shared appBar and bottomNavigationBar
the way i am currently using is implementing them in spearte files and importing them in each screen but i need to make one screen contains the appbar and the bottomNavigationBar and the content of the body renders diffrent views according to the routes and i can't make it at main page because the main page renders welcome screen
in reactJS i was importing the header and footer and make my routes between them how can i make somthing similar in flutter
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: navBar(),
body: SingleChildScrollView(reverse: true, child: ScanPassport()),
bottomNavigationBar: bottomNavigation(),
currentIndex: _selectedIndex,
onTap: _onItemTapped,
showSelectedLabels: false,
showUnselectedLabels: false,
type: BottomNavigationBarType.fixed,
),
);
}
}
A couple of options:
Use MaterialApp() router. There's a tutorial here showing how to refactor your Scaffold() so you don't have duplicate code for appBar, bottomNavigationBar, etc. This is the official Flutter method for view routing.
If you need to swap out your Scaffold() body but can't change your other Scaffold() elements, you can create a widget for the body that takes a "page" value and change what it returns from build() based on the "page" value passed. The widget holding your Scaffold can be stateful and your bottom navigation bar can setState() the page number.
In your context, You can just have a single scaffold homepage screen after logged in success or after welcome screen (depends up app). Once you navigate to homepage, You will have appBar and bottom navigation bar at top and bottom respectively. The remaining portion at center will be your body content of the selected tab. Once you switched the tap on bottom navigation, you should change the content rather than using routes for switching the body content. The current page status will be preserved on homepage.

Flutter ModalBottomSheet visibility

I want to call a function after modal bottom sheet built. But i could not check bottom sheet build. How can i check modal bottom sheet visibility and it is build?
showModalBottomSheet(context: context, builder: (context) => Container())
.then((value) => print('i am visible now!'));