112 lines
3.4 KiB
Dart
112 lines
3.4 KiB
Dart
import 'package:e_commerce/const/AppColors.dart';
|
|
import 'package:e_commerce/ui/bottom_nav_pages/cart.dart';
|
|
import 'package:e_commerce/ui/bottom_nav_pages/favourite.dart';
|
|
import 'package:e_commerce/ui/bottom_nav_pages/home.dart';
|
|
import 'package:e_commerce/ui/bottom_nav_pages/profile.dart';
|
|
import 'package:e_commerce/ui/login_screen.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class BottomNavController extends StatefulWidget {
|
|
@override
|
|
_BottomNavControllerState createState() => _BottomNavControllerState();
|
|
}
|
|
|
|
class _BottomNavControllerState extends State<BottomNavController> {
|
|
final _pages = [
|
|
Home(),
|
|
Favourite(),
|
|
Cart(),
|
|
Profile(),
|
|
];
|
|
var _currentIndex = 0;
|
|
DateTime? lastBackPressTime;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Future<bool> onWillPop() async {
|
|
DateTime now = DateTime.now();
|
|
if (lastBackPressTime == null ||
|
|
now.difference(lastBackPressTime!) > Duration(seconds: 1)) {
|
|
lastBackPressTime = now;
|
|
return Future.value(true); // Allow back press
|
|
} else {
|
|
return showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text("Konfirmasi"),
|
|
content: Text("Apakah Anda yakin ingin keluar?"),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop(false); // Cancel action
|
|
},
|
|
child: Text("Batal"),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => LoginScreen()));
|
|
},
|
|
child: Text("Keluar"),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
).then((value) => value ?? false); // If no response, default to false
|
|
}
|
|
}
|
|
|
|
return WillPopScope(
|
|
onWillPop: onWillPop,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
title: Text(
|
|
"PojokTI",
|
|
style: TextStyle(color: Colors.black),
|
|
),
|
|
centerTitle: true,
|
|
automaticallyImplyLeading: false,
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
elevation: 5,
|
|
selectedItemColor: AppColors.deep_orange,
|
|
backgroundColor: Colors.white,
|
|
unselectedItemColor: Colors.grey,
|
|
currentIndex: _currentIndex,
|
|
selectedLabelStyle:
|
|
TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
|
|
items: [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home),
|
|
label: "Home",
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.favorite_outline), label: "Favourite"),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.add_shopping_cart),
|
|
label: "Cart",
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.person),
|
|
label: "Person",
|
|
),
|
|
],
|
|
onTap: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
print(_currentIndex);
|
|
});
|
|
},
|
|
),
|
|
body: _pages[_currentIndex],
|
|
),
|
|
);
|
|
}
|
|
}
|