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.

121 lines
2.6 KiB

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