fix(navigation-view): back button closing the app from any page (#1019)

This commit is contained in:
Aabed Khan 2023-07-13 19:25:48 +05:45 committed by GitHub
parent 0462815014
commit c5b0621323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,58 +13,68 @@ class NavigationView extends StatelessWidget {
return ViewModelBuilder<NavigationViewModel>.reactive( return ViewModelBuilder<NavigationViewModel>.reactive(
onViewModelReady: (model) => model.initialize(context), onViewModelReady: (model) => model.initialize(context),
viewModelBuilder: () => locator<NavigationViewModel>(), viewModelBuilder: () => locator<NavigationViewModel>(),
builder: (context, model, child) => Scaffold( builder: (context, model, child) => WillPopScope(
body: PageTransitionSwitcher( onWillPop: ()async{
duration: const Duration(milliseconds: 400), if(model.currentIndex == 0){
transitionBuilder: ( return true;
Widget child, }else{
Animation<double> animation, model.setIndex(0);
Animation<double> secondaryAnimation, return false;
) { }
return FadeThroughTransition( },
animation: animation, child: Scaffold(
secondaryAnimation: secondaryAnimation, body: PageTransitionSwitcher(
fillColor: Theme.of(context).colorScheme.surface, duration: const Duration(milliseconds: 400),
child: child, transitionBuilder: (
); Widget child,
}, Animation<double> animation,
child: model.getViewForIndex(model.currentIndex), Animation<double> secondaryAnimation,
), ) {
bottomNavigationBar: NavigationBar( return FadeThroughTransition(
onDestinationSelected: model.setIndex, animation: animation,
selectedIndex: model.currentIndex, secondaryAnimation: secondaryAnimation,
destinations: <Widget>[ fillColor: Theme.of(context).colorScheme.surface,
NavigationDestination( child: child,
icon: model.isIndexSelected(0) );
? const Icon(Icons.dashboard) },
: const Icon(Icons.dashboard_outlined), child: model.getViewForIndex(model.currentIndex),
label: FlutterI18n.translate( ),
context, bottomNavigationBar: NavigationBar(
'navigationView.dashboardTab', onDestinationSelected: model.setIndex,
selectedIndex: model.currentIndex,
destinations: <Widget>[
NavigationDestination(
icon: model.isIndexSelected(0)
? const Icon(Icons.dashboard)
: const Icon(Icons.dashboard_outlined),
label: FlutterI18n.translate(
context,
'navigationView.dashboardTab',
),
tooltip: '',
), ),
tooltip: '', NavigationDestination(
), icon: model.isIndexSelected(1)
NavigationDestination( ? const Icon(Icons.build)
icon: model.isIndexSelected(1) : const Icon(Icons.build_outlined),
? const Icon(Icons.build) label: FlutterI18n.translate(
: const Icon(Icons.build_outlined), context,
label: FlutterI18n.translate( 'navigationView.patcherTab',
context, ),
'navigationView.patcherTab', tooltip: '',
), ),
tooltip: '', NavigationDestination(
), icon: model.isIndexSelected(2)
NavigationDestination( ? const Icon(Icons.settings)
icon: model.isIndexSelected(2) : const Icon(Icons.settings_outlined),
? const Icon(Icons.settings) label: FlutterI18n.translate(
: const Icon(Icons.settings_outlined), context,
label: FlutterI18n.translate( 'navigationView.settingsTab',
context, ),
'navigationView.settingsTab', tooltip: '',
), ),
tooltip: '', ],
), ),
],
), ),
), ),
); );