I am working on a bottom navigation bar, but I am not getting perfectly on back press to previous route.
If i select more then two navigation button from bottom navigationbar view items then when i press back button it'll close the app.
return Scaffold(
body: (_getBody(index, model)),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: Colors.white,
selectedItemColor: Color(0xFFf5851f),
unselectedItemColor: Colors.grey,
type: BottomNavigationBarType.fixed,
currentIndex: index,
// onTap: (value) => setState(() => index = value),
onTap: (value) {
setState(() => index = value);
print(value);
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.restaurant),
title: Text('GMA', style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.call),
title: Text('CALL ON ORDER',
style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.notifications),
title:
Text('NOTIFICATION', style: Theme.of(context).textTheme.body2)),
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart),
title: Text('CART', style: Theme.of(context).textTheme.body2)),
//TextStyle(fontSize: 12, fontWeight: FontWeight.w600))),
],
),
Widget _getBody(int index, MainModel model) {
switch (index) {
case 0:
return firstpage(); // Create this function, it should return your first page as a widget
case 1:
return ProductSearch(); // Create this function, it should return your second page as a widget
case 2:
return Account(); // Create this function, it should return your third page as a widget
case 3:
return Cart(); // Create this function, it should return your fourth page as a widget
}
}