You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.4 KiB

8 months ago
import 'package:flutter/material.dart';
import '../widgets/bottom_navigation.dart';
8 months ago
import '../widgets/mobile_bottom_navigation.dart';
8 months ago
class MainLayout extends StatefulWidget {
final Widget child;
8 months ago
final String? currentRoute;
8 months ago
8 months ago
const MainLayout({super.key, required this.child, this.currentRoute});
8 months ago
@override
_MainLayoutState createState() => _MainLayoutState();
}
class _MainLayoutState extends State<MainLayout> {
int _selectedIndex = 0;
@override
void initState() {
super.initState();
8 months ago
_selectedIndex = _getIndexFromRoute(widget.currentRoute ?? '/tables');
8 months ago
}
8 months ago
int _getIndexFromRoute(String route) {
switch (route) {
8 months ago
case '/tables':
8 months ago
return 0;
8 months ago
case '/commandes':
case '/orders':
8 months ago
return 1;
8 months ago
case '/categories':
8 months ago
return 2;
8 months ago
case '/menu':
return 3;
8 months ago
case '/plats':
8 months ago
return 4;
8 months ago
case '/encaissement':
return 5;
8 months ago
case '/historique':
return 6;
8 months ago
default:
return 0;
}
8 months ago
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
8 months ago
String route;
8 months ago
switch (index) {
case 0:
8 months ago
route = '/tables';
8 months ago
break;
case 1:
8 months ago
route = '/commandes';
8 months ago
break;
case 2:
8 months ago
route = '/categories';
8 months ago
break;
8 months ago
case 3:
route = '/menu';
break;
case 4:
8 months ago
route = '/plats';
8 months ago
break;
8 months ago
case 5:
route = '/encaissement';
break;
8 months ago
case 6:
route = '/historique';
break;
8 months ago
default:
8 months ago
route = '/tables';
8 months ago
}
if (route != widget.currentRoute) {
Navigator.pushReplacementNamed(context, route);
8 months ago
}
}
8 months ago
@override
Widget build(BuildContext context) {
final isDesktop = MediaQuery.of(context).size.width > 600;
return Scaffold(
body: Column(
8 months ago
children: [
8 months ago
Expanded(child: widget.child),
// Show desktop navigation on larger screens
if (isDesktop)
AppBottomNavigation(
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
8 months ago
),
],
),
8 months ago
// Show mobile navigation on smaller screens
8 months ago
bottomNavigationBar:
isDesktop
? null
: MobileBottomNavigation(
currentRoute: widget.currentRoute ?? '/tables',
selectedIndex: _selectedIndex,
onItemTapped: _onItemTapped,
),
8 months ago
);
}
8 months ago
}