Код: Выделить всё
List labels = ['Home', 'Cart', 'Notification', 'Account'];
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvoked: ((didPop) {
if (selctedIndex != 0) {
setState(() {
selctedIndex = 0;
});
} else{
final now = DateTime.now();
if(currentPress == null || now.difference(currentPress!) > const Duration(seconds: 2)){
currentPress = now;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
elevation: 1,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
backgroundColor: Colors.black,
content: const Text('Double Press to exit', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w600),),
duration: const Duration(seconds: 1),
),
);
} else {
SystemNavigator.pop();
}
}
}),
child: Scaffold(
body: items[selctedIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: selctedIndex,
selectedLabelStyle: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black
),
elevation: 3,
items: List.generate(items.length, (index) {
return BottomNavigationBarItem(
icon: CustomIcon(
icon: icons[index],
isSelected: index == selctedIndex,
),
label: labels[index],
);
}),
onTap: (value) {
setState(() {
selctedIndex = value;
});
},
),
),
);
}
Код: Выделить всё
class _HomeScreenState extends State {
bool isExit = false;
bool categorySelected = false;
String categoryTitle ='';
CartItems categoryProduct = items[0];
@override
Widget build(BuildContext context) {
// double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return PopScope(
canPop: (categorySelected || isExit) ? false : true,
onPopInvoked: (didPop) {
setState(() {
categorySelected = false;
isExit = false;
});
},
child: categorySelected
? CategoryProductsScreen(title: categoryTitle, items: categoryProduct)
: Scaffold(
appBar: homeAppBar(
icon: CupertinoIcons.square_stack_3d_down_dottedline,
navigate: (){
// Navigator.of(context).push(MaterialPageRoute(builder: (context) => BottomBar(index: 3),));
}
),
// other widgets goes here
)
)
)
}
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... in-flutter