main menu action
This commit is contained in:
parent
831bf02a5c
commit
21c03f72d6
@ -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),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:furibase/providers/character_provider.dart';
|
||||
import 'package:furibase/providers/menu_selection_provider.dart';
|
||||
import 'package:furibase/screen/Home_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@ -16,8 +17,11 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (context) => CharacterProvider(),
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => CharacterProvider()),
|
||||
ChangeNotifierProvider(create: (context) => MenuSelectionProvider()),
|
||||
],
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'AR Character App',
|
||||
|
||||
12
lib/providers/menu_selection_provider.dart
Normal file
12
lib/providers/menu_selection_provider.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MenuSelectionProvider with ChangeNotifier {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
int get selectedIndex => _selectedIndex;
|
||||
|
||||
set selectedIndex(int index) {
|
||||
_selectedIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@ -238,8 +238,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
||||
Positioned(
|
||||
bottom: 5,
|
||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
||||
bottom: 8,
|
||||
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, -20),
|
||||
child: ScanButton(),
|
||||
|
||||
@ -150,8 +150,8 @@ class _KoleksiScreenState extends State<KoleksiScreen> {
|
||||
),
|
||||
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
||||
Positioned(
|
||||
bottom: 5,
|
||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
||||
bottom: 8,
|
||||
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, -20),
|
||||
child: ScanButton(),
|
||||
|
||||
@ -290,8 +290,8 @@ class _PustakaScreenState extends State<PustakaScreen> {
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
bottom: 5,
|
||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
||||
bottom: 8,
|
||||
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, -20),
|
||||
child: ScanButton(),
|
||||
|
||||
@ -341,8 +341,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
||||
Positioned(
|
||||
bottom: 5,
|
||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
||||
bottom: 8,
|
||||
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, -20),
|
||||
child: ScanButton(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user