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/bottom_navbar.dart';
|
||||||
import 'package:furibase/components/menu_button.dart';
|
import 'package:furibase/components/menu_button.dart';
|
||||||
import 'package:furibase/components/scan_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/Home_screen.dart';
|
||||||
import 'package:furibase/screen/koleksi_screen.dart';
|
import 'package:furibase/screen/koleksi_screen.dart';
|
||||||
import 'package:furibase/screen/pustaka_screen.dart';
|
import 'package:furibase/screen/pustaka_screen.dart';
|
||||||
import 'package:furibase/screen/saya/profile_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});
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final Size size = MediaQuery.of(context).size;
|
final Size size = MediaQuery.of(context).size;
|
||||||
|
final selectedIndex =
|
||||||
|
Provider.of<MenuSelectionProvider>(context).selectedIndex;
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||||
@ -23,50 +52,64 @@ class MainMenu extends StatelessWidget {
|
|||||||
MenuButton(
|
MenuButton(
|
||||||
label: "E-furibuddy",
|
label: "E-furibuddy",
|
||||||
icon: 'assets/icons/furrybuddy.svg',
|
icon: 'assets/icons/furrybuddy.svg',
|
||||||
onPress:
|
onPress: () => _onItemTapped(context, 0),
|
||||||
() => {
|
isSelected: selectedIndex == 0,
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => HomeScreen()),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
MenuButton(
|
MenuButton(
|
||||||
label: "Koleksi",
|
label: "Koleksi",
|
||||||
icon: 'assets/icons/Koleksi.svg',
|
icon: 'assets/icons/Koleksi.svg',
|
||||||
onPress:
|
onPress: () => _onItemTapped(context, 1),
|
||||||
() => {
|
isSelected: selectedIndex == 1,
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => KoleksiScreen()),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
SizedBox(width: 120),
|
SizedBox(width: 100),
|
||||||
MenuButton(
|
MenuButton(
|
||||||
label: "Pustaka",
|
label: "Pustaka",
|
||||||
icon: 'assets/icons/Pustaka.svg',
|
icon: 'assets/icons/Pustaka.svg',
|
||||||
onPress:
|
onPress: () => _onItemTapped(context, 2),
|
||||||
() => {
|
isSelected: selectedIndex == 2,
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => PustakaScreen()),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
MenuButton(
|
MenuButton(
|
||||||
label: "Saya",
|
label: "Saya",
|
||||||
icon: 'assets/icons/Saya.svg',
|
icon: 'assets/icons/Saya.svg',
|
||||||
onPress:
|
onPress: () => _onItemTapped(context, 3),
|
||||||
() => {
|
isSelected: selectedIndex == 3,
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (context) => ProfileScreen()),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
height: h ?? 28,
|
||||||
// allowDrawingOutsideViewBox: true,
|
// allowDrawingOutsideViewBox: true,
|
||||||
colorFilter: ColorFilter.mode(
|
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,
|
BlendMode.srcIn,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -41,7 +43,10 @@ class MenuButton extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
label ?? '',
|
label ?? '',
|
||||||
style: TextStyle(
|
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,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -8,8 +8,8 @@ class ScanButton extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
width: 86,
|
width: 76,
|
||||||
height: 86,
|
height: 76,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: const Color.fromARGB(223, 67, 63, 179),
|
color: const Color.fromARGB(223, 67, 63, 179),
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:furibase/providers/character_provider.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:furibase/screen/Home_screen.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@ -16,8 +17,11 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ChangeNotifierProvider(
|
return MultiProvider(
|
||||||
create: (context) => CharacterProvider(),
|
providers: [
|
||||||
|
ChangeNotifierProvider(create: (context) => CharacterProvider()),
|
||||||
|
ChangeNotifierProvider(create: (context) => MenuSelectionProvider()),
|
||||||
|
],
|
||||||
child: MaterialApp(
|
child: MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
title: 'AR Character App',
|
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: 0, left: 0, right: 0, child: MainMenu()),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 5,
|
bottom: 8,
|
||||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||||
child: Transform.translate(
|
child: Transform.translate(
|
||||||
offset: Offset(0, -20),
|
offset: Offset(0, -20),
|
||||||
child: ScanButton(),
|
child: ScanButton(),
|
||||||
|
|||||||
@ -150,8 +150,8 @@ class _KoleksiScreenState extends State<KoleksiScreen> {
|
|||||||
),
|
),
|
||||||
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 5,
|
bottom: 8,
|
||||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||||
child: Transform.translate(
|
child: Transform.translate(
|
||||||
offset: Offset(0, -20),
|
offset: Offset(0, -20),
|
||||||
child: ScanButton(),
|
child: ScanButton(),
|
||||||
|
|||||||
@ -290,8 +290,8 @@ class _PustakaScreenState extends State<PustakaScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 5,
|
bottom: 8,
|
||||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||||
child: Transform.translate(
|
child: Transform.translate(
|
||||||
offset: Offset(0, -20),
|
offset: Offset(0, -20),
|
||||||
child: ScanButton(),
|
child: ScanButton(),
|
||||||
|
|||||||
@ -341,8 +341,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
),
|
),
|
||||||
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
Positioned(bottom: 0, left: 0, right: 0, child: MainMenu()),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 5,
|
bottom: 8,
|
||||||
left: MediaQuery.of(context).size.width / 2 - 43,
|
left: MediaQuery.of(context).size.width / 2 - 38,
|
||||||
child: Transform.translate(
|
child: Transform.translate(
|
||||||
offset: Offset(0, -20),
|
offset: Offset(0, -20),
|
||||||
child: ScanButton(),
|
child: ScanButton(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user