|
|
|
@ -1,14 +1,19 @@ |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import '../widgets/bottom_navigation.dart'; |
|
|
|
import '../widgets/mobile_bottom_navigation.dart'; |
|
|
|
|
|
|
|
class MainLayout extends StatefulWidget { |
|
|
|
final Widget child; |
|
|
|
final int currentIndex; |
|
|
|
final String? currentRoute; |
|
|
|
|
|
|
|
const MainLayout({super.key, required this.child, this.currentIndex = 0}); |
|
|
|
const MainLayout({ |
|
|
|
super.key, |
|
|
|
required this.child, |
|
|
|
this.currentRoute, |
|
|
|
// Remove the currentIndex parameter - it's not needed |
|
|
|
}); |
|
|
|
|
|
|
|
@override |
|
|
|
// ignore: library_private_types_in_public_api |
|
|
|
_MainLayoutState createState() => _MainLayoutState(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -18,39 +23,24 @@ class _MainLayoutState extends State<MainLayout> { |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
_selectedIndex = widget.currentIndex; |
|
|
|
_selectedIndex = _getIndexFromRoute(widget.currentRoute ?? '/dashboard'); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
final isDesktop = MediaQuery.of(context).size.width >= 768; |
|
|
|
|
|
|
|
return Scaffold( |
|
|
|
backgroundColor: Colors.grey.shade50, |
|
|
|
body: Row( |
|
|
|
children: [ |
|
|
|
// Desktop Sidebar |
|
|
|
if (isDesktop) _buildDesktopSidebar(), |
|
|
|
|
|
|
|
// Main Content |
|
|
|
Expanded( |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
// Page Content |
|
|
|
Expanded(child: widget.child), |
|
|
|
|
|
|
|
// Bottom Navigation |
|
|
|
AppBottomNavigation( |
|
|
|
selectedIndex: _selectedIndex, |
|
|
|
onItemTapped: _onItemTapped, |
|
|
|
isDesktop: isDesktop, |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
int _getIndexFromRoute(String route) { |
|
|
|
switch (route) { |
|
|
|
case '/dashboard': |
|
|
|
return 0; |
|
|
|
case '/menu': |
|
|
|
return 1; |
|
|
|
case '/tables': |
|
|
|
return 2; |
|
|
|
case '/orders': |
|
|
|
return 3; |
|
|
|
case '/profile': |
|
|
|
return 4; |
|
|
|
default: |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void _onItemTapped(int index) { |
|
|
|
@ -58,103 +48,57 @@ class _MainLayoutState extends State<MainLayout> { |
|
|
|
_selectedIndex = index; |
|
|
|
}); |
|
|
|
|
|
|
|
// Global navigation logic |
|
|
|
String route; |
|
|
|
switch (index) { |
|
|
|
case 0: |
|
|
|
Navigator.pushReplacementNamed(context, '/tables'); |
|
|
|
route = '/dashboard'; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
Navigator.pushReplacementNamed(context, '/commandes'); |
|
|
|
route = '/menu'; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
Navigator.pushReplacementNamed(context, '/categories'); |
|
|
|
route = '/tables'; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
Navigator.pushReplacementNamed(context, '/menus'); |
|
|
|
route = '/orders'; |
|
|
|
break; |
|
|
|
} |
|
|
|
case 4: |
|
|
|
route = '/profile'; |
|
|
|
break; |
|
|
|
default: |
|
|
|
route = '/dashboard'; |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildDesktopSidebar() { |
|
|
|
return Container( |
|
|
|
width: 250, |
|
|
|
color: Colors.white, |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
Container( |
|
|
|
padding: const EdgeInsets.all(20), |
|
|
|
child: const Text( |
|
|
|
'Restaurant App', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 20, |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
color: Colors.black87, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
Expanded( |
|
|
|
child: ListView( |
|
|
|
children: [ |
|
|
|
_buildSidebarItem( |
|
|
|
icon: Icons.table_restaurant, |
|
|
|
title: 'Tables', |
|
|
|
route: '/tables', |
|
|
|
index: 0, |
|
|
|
), |
|
|
|
_buildSidebarItem( |
|
|
|
icon: Icons.receipt_long_outlined, |
|
|
|
title: 'Commandes', |
|
|
|
route: '/commandes', |
|
|
|
index: 1, |
|
|
|
), |
|
|
|
_buildSidebarItem( |
|
|
|
icon: Icons.category_outlined, |
|
|
|
title: 'Catégories', |
|
|
|
route: '/categories', |
|
|
|
index: 2, |
|
|
|
), |
|
|
|
_buildSidebarItem( |
|
|
|
icon: Icons.restaurant_menu, |
|
|
|
title: 'Menus', |
|
|
|
route: '/menus', |
|
|
|
index: 3, |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
if (route != widget.currentRoute) { |
|
|
|
Navigator.pushReplacementNamed(context, route); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Widget _buildSidebarItem({ |
|
|
|
required IconData icon, |
|
|
|
required String title, |
|
|
|
required String route, |
|
|
|
required int index, |
|
|
|
}) { |
|
|
|
final isSelected = _selectedIndex == index; |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
final isDesktop = MediaQuery.of(context).size.width > 600; |
|
|
|
|
|
|
|
return ListTile( |
|
|
|
leading: Icon( |
|
|
|
icon, |
|
|
|
color: isSelected ? Colors.green.shade700 : Colors.grey.shade600, |
|
|
|
return Scaffold( |
|
|
|
body: Column( |
|
|
|
children: [ |
|
|
|
Expanded(child: widget.child), |
|
|
|
// Show desktop navigation on larger screens |
|
|
|
if (isDesktop) |
|
|
|
AppBottomNavigation( |
|
|
|
selectedIndex: _selectedIndex, |
|
|
|
onItemTapped: _onItemTapped, |
|
|
|
), |
|
|
|
title: Text( |
|
|
|
title, |
|
|
|
style: TextStyle( |
|
|
|
color: isSelected ? Colors.green.shade700 : Colors.grey.shade700, |
|
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal, |
|
|
|
], |
|
|
|
), |
|
|
|
// Show mobile navigation on smaller screens |
|
|
|
bottomNavigationBar: |
|
|
|
isDesktop |
|
|
|
? null |
|
|
|
: MobileBottomNavigation( |
|
|
|
currentRoute: widget.currentRoute ?? '/dashboard', |
|
|
|
selectedIndex: _selectedIndex, |
|
|
|
onItemTapped: _onItemTapped, |
|
|
|
), |
|
|
|
selected: isSelected, |
|
|
|
selectedTileColor: Colors.green.shade50, |
|
|
|
onTap: () { |
|
|
|
setState(() { |
|
|
|
_selectedIndex = index; |
|
|
|
}); |
|
|
|
Navigator.pushReplacementNamed(context, route); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|