main menu action
This commit is contained in:
@@ -2,17 +2,46 @@ import 'package:flutter/material.dart';
|
||||
import 'package:furibase/components/bottom_navbar.dart';
|
||||
import 'package:furibase/components/menu_button.dart';
|
||||
import 'package:furibase/components/scan_button.dart';
|
||||
import 'package:furibase/providers/menu_selection_provider.dart';
|
||||
import 'package:furibase/screen/Home_screen.dart';
|
||||
import 'package:furibase/screen/koleksi_screen.dart';
|
||||
import 'package:furibase/screen/pustaka_screen.dart';
|
||||
import 'package:furibase/screen/saya/profile_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MainMenu extends StatelessWidget {
|
||||
class MainMenu extends StatefulWidget {
|
||||
const MainMenu({super.key});
|
||||
_MainMenuState createState() => _MainMenuState();
|
||||
}
|
||||
|
||||
class _MainMenuState extends State<MainMenu> {
|
||||
int selectedIndex = 0;
|
||||
|
||||
final List<Widget> _screens = [
|
||||
HomeScreen(),
|
||||
KoleksiScreen(),
|
||||
PustakaScreen(),
|
||||
ProfileScreen(),
|
||||
];
|
||||
|
||||
// void _onItemTapped(int index) {
|
||||
// Future.delayed(Duration(milliseconds: 100), () {
|
||||
// Navigator.pushReplacement(
|
||||
// context,
|
||||
// MaterialPageRoute(builder: (context) => _screens[index]),
|
||||
// );
|
||||
// });
|
||||
|
||||
// setState(() {
|
||||
// selectedIndex = index;
|
||||
// });
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size size = MediaQuery.of(context).size;
|
||||
final selectedIndex =
|
||||
Provider.of<MenuSelectionProvider>(context).selectedIndex;
|
||||
return Container(
|
||||
color: Colors.transparent,
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
@@ -23,50 +52,64 @@ class MainMenu extends StatelessWidget {
|
||||
MenuButton(
|
||||
label: "E-furibuddy",
|
||||
icon: 'assets/icons/furrybuddy.svg',
|
||||
onPress:
|
||||
() => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomeScreen()),
|
||||
),
|
||||
},
|
||||
onPress: () => _onItemTapped(context, 0),
|
||||
isSelected: selectedIndex == 0,
|
||||
),
|
||||
MenuButton(
|
||||
label: "Koleksi",
|
||||
icon: 'assets/icons/Koleksi.svg',
|
||||
onPress:
|
||||
() => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => KoleksiScreen()),
|
||||
),
|
||||
},
|
||||
onPress: () => _onItemTapped(context, 1),
|
||||
isSelected: selectedIndex == 1,
|
||||
),
|
||||
SizedBox(width: 120),
|
||||
SizedBox(width: 100),
|
||||
MenuButton(
|
||||
label: "Pustaka",
|
||||
icon: 'assets/icons/Pustaka.svg',
|
||||
onPress:
|
||||
() => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => PustakaScreen()),
|
||||
),
|
||||
},
|
||||
onPress: () => _onItemTapped(context, 2),
|
||||
isSelected: selectedIndex == 2,
|
||||
),
|
||||
MenuButton(
|
||||
label: "Saya",
|
||||
icon: 'assets/icons/Saya.svg',
|
||||
onPress:
|
||||
() => {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ProfileScreen()),
|
||||
),
|
||||
},
|
||||
onPress: () => _onItemTapped(context, 3),
|
||||
isSelected: selectedIndex == 3,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onItemTapped(BuildContext context, int index) {
|
||||
// Mengubah selectedIndex di MenuSelectionProvider
|
||||
Provider.of<MenuSelectionProvider>(context, listen: false).selectedIndex =
|
||||
index;
|
||||
|
||||
// Pindah halaman sesuai index yang dipilih
|
||||
switch (index) {
|
||||
case 0:
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => HomeScreen()),
|
||||
);
|
||||
break;
|
||||
case 1:
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => KoleksiScreen()),
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => PustakaScreen()),
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => ProfileScreen()),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ class MenuButton extends StatelessWidget {
|
||||
height: h ?? 28,
|
||||
// allowDrawingOutsideViewBox: true,
|
||||
colorFilter: ColorFilter.mode(
|
||||
Color.fromARGB(255, 255, 255, 255),
|
||||
(isSelected ?? false)
|
||||
? Color.fromARGB(255, 216, 182, 10)
|
||||
: Color.fromARGB(255, 255, 255, 255),
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
@@ -41,7 +43,10 @@ class MenuButton extends StatelessWidget {
|
||||
Text(
|
||||
label ?? '',
|
||||
style: TextStyle(
|
||||
color: Color.fromARGB(255, 239, 224, 232),
|
||||
color:
|
||||
(isSelected ?? false)
|
||||
? Color.fromARGB(255, 216, 182, 10)
|
||||
: Color.fromARGB(255, 239, 224, 232),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -8,8 +8,8 @@ class ScanButton extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: 86,
|
||||
height: 86,
|
||||
width: 76,
|
||||
height: 76,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: const Color.fromARGB(223, 67, 63, 179),
|
||||
|
||||
Reference in New Issue
Block a user