Compare commits
No commits in common. "914d336f73d7c9c291ce3eb0a807e1365b133e20" and "7378bc9b43be24c9e8f5b006c68a44948c6cb2ba" have entirely different histories.
914d336f73
...
7378bc9b43
@ -1,19 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../widgets/bottom_navigation.dart';
|
import '../widgets/bottom_navigation.dart';
|
||||||
import '../widgets/mobile_bottom_navigation.dart';
|
|
||||||
|
|
||||||
class MainLayout extends StatefulWidget {
|
class MainLayout extends StatefulWidget {
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final String? currentRoute;
|
final int currentIndex;
|
||||||
|
|
||||||
const MainLayout({
|
const MainLayout({super.key, required this.child, this.currentIndex = 0});
|
||||||
super.key,
|
|
||||||
required this.child,
|
|
||||||
this.currentRoute,
|
|
||||||
// Remove the currentIndex parameter - it's not needed
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
// ignore: library_private_types_in_public_api
|
||||||
_MainLayoutState createState() => _MainLayoutState();
|
_MainLayoutState createState() => _MainLayoutState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,24 +18,39 @@ class _MainLayoutState extends State<MainLayout> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedIndex = _getIndexFromRoute(widget.currentRoute ?? '/dashboard');
|
_selectedIndex = widget.currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _getIndexFromRoute(String route) {
|
@override
|
||||||
switch (route) {
|
Widget build(BuildContext context) {
|
||||||
case '/dashboard':
|
final isDesktop = MediaQuery.of(context).size.width >= 768;
|
||||||
return 0;
|
|
||||||
case '/menu':
|
return Scaffold(
|
||||||
return 1;
|
backgroundColor: Colors.grey.shade50,
|
||||||
case '/tables':
|
body: Row(
|
||||||
return 2;
|
children: [
|
||||||
case '/orders':
|
// Desktop Sidebar
|
||||||
return 3;
|
if (isDesktop) _buildDesktopSidebar(),
|
||||||
case '/profile':
|
|
||||||
return 4;
|
// Main Content
|
||||||
default:
|
Expanded(
|
||||||
return 0;
|
child: Column(
|
||||||
}
|
children: [
|
||||||
|
// Page Content
|
||||||
|
Expanded(child: widget.child),
|
||||||
|
|
||||||
|
// Bottom Navigation
|
||||||
|
AppBottomNavigation(
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onItemTapped: _onItemTapped,
|
||||||
|
isDesktop: isDesktop,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
void _onItemTapped(int index) {
|
||||||
@ -48,57 +58,103 @@ class _MainLayoutState extends State<MainLayout> {
|
|||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
});
|
});
|
||||||
|
|
||||||
String route;
|
// Global navigation logic
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
route = '/dashboard';
|
Navigator.pushReplacementNamed(context, '/tables');
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
route = '/menu';
|
Navigator.pushReplacementNamed(context, '/commandes');
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
route = '/tables';
|
Navigator.pushReplacementNamed(context, '/categories');
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
route = '/orders';
|
Navigator.pushReplacementNamed(context, '/menus');
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
route = '/profile';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
route = '/dashboard';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (route != widget.currentRoute) {
|
|
||||||
Navigator.pushReplacementNamed(context, route);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
Widget _buildDesktopSidebar() {
|
||||||
Widget build(BuildContext context) {
|
return Container(
|
||||||
final isDesktop = MediaQuery.of(context).size.width > 600;
|
width: 250,
|
||||||
|
color: Colors.white,
|
||||||
return Scaffold(
|
child: Column(
|
||||||
body: Column(
|
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: widget.child),
|
Container(
|
||||||
// Show desktop navigation on larger screens
|
padding: const EdgeInsets.all(20),
|
||||||
if (isDesktop)
|
child: const Text(
|
||||||
AppBottomNavigation(
|
'Restaurant App',
|
||||||
selectedIndex: _selectedIndex,
|
style: TextStyle(
|
||||||
onItemTapped: _onItemTapped,
|
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,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
// Show mobile navigation on smaller screens
|
),
|
||||||
bottomNavigationBar:
|
],
|
||||||
isDesktop
|
|
||||||
? null
|
|
||||||
: MobileBottomNavigation(
|
|
||||||
currentRoute: widget.currentRoute ?? '/dashboard',
|
|
||||||
selectedIndex: _selectedIndex,
|
|
||||||
onItemTapped: _onItemTapped,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildSidebarItem({
|
||||||
|
required IconData icon,
|
||||||
|
required String title,
|
||||||
|
required String route,
|
||||||
|
required int index,
|
||||||
|
}) {
|
||||||
|
final isSelected = _selectedIndex == index;
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
leading: Icon(
|
||||||
|
icon,
|
||||||
|
color: isSelected ? Colors.green.shade700 : Colors.grey.shade600,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
title,
|
||||||
|
style: TextStyle(
|
||||||
|
color: isSelected ? Colors.green.shade700 : Colors.grey.shade700,
|
||||||
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
selected: isSelected,
|
||||||
|
selectedTileColor: Colors.green.shade50,
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = index;
|
||||||
|
});
|
||||||
|
Navigator.pushReplacementNamed(context, route);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,23 +23,14 @@ class MyApp extends StatelessWidget {
|
|||||||
initialRoute: '/tables',
|
initialRoute: '/tables',
|
||||||
routes: {
|
routes: {
|
||||||
'/tables':
|
'/tables':
|
||||||
(context) => const MainLayout(
|
(context) =>
|
||||||
currentRoute: '/tables',
|
const MainLayout(currentIndex: 0, child: TablesScreen()),
|
||||||
child: TablesScreen(),
|
// '/commandes':
|
||||||
),
|
// (context) => MainLayout(currentIndex: 1, child: CommandesScreen()),
|
||||||
// Uncomment and update these as needed:
|
// '/categories':
|
||||||
// '/commandes': (context) => const MainLayout(
|
// (context) => MainLayout(currentIndex: 2, child: CategoriesScreen()),
|
||||||
// currentRoute: '/commandes',
|
// '/menus':
|
||||||
// child: CommandesScreen(),
|
// (context) => MainLayout(currentIndex: 3, child: MenusScreen()),
|
||||||
// ),
|
|
||||||
// '/categories': (context) => const MainLayout(
|
|
||||||
// currentRoute: '/categories',
|
|
||||||
// child: CategoriesScreen(),
|
|
||||||
// ),
|
|
||||||
// '/menus': (context) => const MainLayout(
|
|
||||||
// currentRoute: '/menus',
|
|
||||||
// child: MenusScreen(),
|
|
||||||
// ),
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -253,7 +253,7 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 30),
|
SizedBox(height: 30),
|
||||||
const Text(
|
const Text(
|
||||||
'Sélectionner une table',
|
'Sélectionner une table',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
@ -446,39 +446,40 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: isSelectable
|
onPressed:
|
||||||
|
isSelectable
|
||||||
? () {
|
? () {
|
||||||
// Affiche un message
|
// Handle table selection
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(
|
||||||
SnackBar(
|
|
||||||
content: Text('Table ${table.nom} sélectionnée'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Redirige vers MenuPage avec les paramètres requis
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
).showSnackBar(
|
||||||
builder: (context) => MenuPage(
|
SnackBar(
|
||||||
tableId: table.id,
|
content: Text(
|
||||||
personne: table.capacity, // Ajout du paramètre manquant
|
'Table ${table.nom} sélectionnée',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: isSelectable
|
backgroundColor:
|
||||||
|
isSelectable
|
||||||
? Colors.green.shade700
|
? Colors.green.shade700
|
||||||
: Colors.grey.shade300,
|
: Colors.grey.shade300,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 8,
|
||||||
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(
|
||||||
|
8,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
isSelectable ? 'Sélectionner' : 'Indisponible',
|
isSelectable
|
||||||
|
? 'Sélectionner'
|
||||||
|
: 'Indisponible',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class AppBottomNavigation extends StatelessWidget {
|
class AppBottomNavigation extends StatelessWidget {
|
||||||
final int? selectedIndex;
|
final int selectedIndex;
|
||||||
final Function(int) onItemTapped;
|
final Function(int) onItemTapped;
|
||||||
final bool isDesktop;
|
final bool isDesktop;
|
||||||
|
|
||||||
@ -107,50 +107,6 @@ class AppBottomNavigation extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
const SizedBox(width: 20),
|
|
||||||
|
|
||||||
// Commandes Tab
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () => onItemTapped(1),
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color:
|
|
||||||
selectedIndex == 1
|
|
||||||
? Colors.green.shade700
|
|
||||||
: Colors.transparent,
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.receipt_long_outlined,
|
|
||||||
color:
|
|
||||||
selectedIndex == 1
|
|
||||||
? Colors.white
|
|
||||||
: Colors.grey.shade600,
|
|
||||||
size: 16,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(
|
|
||||||
'Categories',
|
|
||||||
style: TextStyle(
|
|
||||||
color:
|
|
||||||
selectedIndex == 1
|
|
||||||
? Colors.white
|
|
||||||
: Colors.grey.shade600,
|
|
||||||
fontWeight:
|
|
||||||
selectedIndex == 1
|
|
||||||
? FontWeight.w500
|
|
||||||
: FontWeight.normal,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
|
||||||
// User Profile Section
|
// User Profile Section
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class MobileBottomNavigation extends StatelessWidget {
|
class MobileBottomNavigation extends StatelessWidget {
|
||||||
final int? selectedIndex;
|
final int selectedIndex;
|
||||||
final Function(int) onItemTapped;
|
final Function(int) onItemTapped;
|
||||||
|
|
||||||
const MobileBottomNavigation({
|
const MobileBottomNavigation({
|
||||||
super.key,
|
super.key,
|
||||||
required this.selectedIndex,
|
required this.selectedIndex,
|
||||||
required this.onItemTapped,
|
required this.onItemTapped,
|
||||||
required String currentRoute,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user