bottom
This commit is contained in:
parent
39d0b7103e
commit
a7268ad74f
@ -1,14 +1,19 @@
|
|||||||
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 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
|
@override
|
||||||
// ignore: library_private_types_in_public_api
|
|
||||||
_MainLayoutState createState() => _MainLayoutState();
|
_MainLayoutState createState() => _MainLayoutState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,39 +23,24 @@ class _MainLayoutState extends State<MainLayout> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedIndex = widget.currentIndex;
|
_selectedIndex = _getIndexFromRoute(widget.currentRoute ?? '/dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
int _getIndexFromRoute(String route) {
|
||||||
Widget build(BuildContext context) {
|
switch (route) {
|
||||||
final isDesktop = MediaQuery.of(context).size.width >= 768;
|
case '/dashboard':
|
||||||
|
return 0;
|
||||||
return Scaffold(
|
case '/menu':
|
||||||
backgroundColor: Colors.grey.shade50,
|
return 1;
|
||||||
body: Row(
|
case '/tables':
|
||||||
children: [
|
return 2;
|
||||||
// Desktop Sidebar
|
case '/orders':
|
||||||
if (isDesktop) _buildDesktopSidebar(),
|
return 3;
|
||||||
|
case '/profile':
|
||||||
// Main Content
|
return 4;
|
||||||
Expanded(
|
default:
|
||||||
child: Column(
|
return 0;
|
||||||
children: [
|
}
|
||||||
// Page Content
|
|
||||||
Expanded(child: widget.child),
|
|
||||||
|
|
||||||
// Bottom Navigation
|
|
||||||
AppBottomNavigation(
|
|
||||||
selectedIndex: _selectedIndex,
|
|
||||||
onItemTapped: _onItemTapped,
|
|
||||||
isDesktop: isDesktop,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onItemTapped(int index) {
|
void _onItemTapped(int index) {
|
||||||
@ -58,103 +48,57 @@ class _MainLayoutState extends State<MainLayout> {
|
|||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Global navigation logic
|
String route;
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
Navigator.pushReplacementNamed(context, '/tables');
|
route = '/dashboard';
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Navigator.pushReplacementNamed(context, '/commandes');
|
route = '/menu';
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Navigator.pushReplacementNamed(context, '/categories');
|
route = '/tables';
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
Navigator.pushReplacementNamed(context, '/menus');
|
route = '/orders';
|
||||||
break;
|
break;
|
||||||
}
|
case 4:
|
||||||
|
route = '/profile';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
route = '/dashboard';
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDesktopSidebar() {
|
if (route != widget.currentRoute) {
|
||||||
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,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
Navigator.pushReplacementNamed(context, route);
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final isDesktop = MediaQuery.of(context).size.width > 600;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Expanded(child: widget.child),
|
||||||
|
// Show desktop navigation on larger screens
|
||||||
|
if (isDesktop)
|
||||||
|
AppBottomNavigation(
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onItemTapped: _onItemTapped,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// Show mobile navigation on smaller screens
|
||||||
|
bottomNavigationBar:
|
||||||
|
isDesktop
|
||||||
|
? null
|
||||||
|
: MobileBottomNavigation(
|
||||||
|
currentRoute: widget.currentRoute ?? '/dashboard',
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onItemTapped: _onItemTapped,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,14 +23,23 @@ class MyApp extends StatelessWidget {
|
|||||||
initialRoute: '/tables',
|
initialRoute: '/tables',
|
||||||
routes: {
|
routes: {
|
||||||
'/tables':
|
'/tables':
|
||||||
(context) =>
|
(context) => const MainLayout(
|
||||||
const MainLayout(currentIndex: 0, child: TablesScreen()),
|
currentRoute: '/tables',
|
||||||
// '/commandes':
|
child: TablesScreen(),
|
||||||
// (context) => MainLayout(currentIndex: 1, child: CommandesScreen()),
|
),
|
||||||
// '/categories':
|
// Uncomment and update these as needed:
|
||||||
// (context) => MainLayout(currentIndex: 2, child: CategoriesScreen()),
|
// '/commandes': (context) => const MainLayout(
|
||||||
// '/menus':
|
// currentRoute: '/commandes',
|
||||||
// (context) => MainLayout(currentIndex: 3, child: MenusScreen()),
|
// child: CommandesScreen(),
|
||||||
|
// ),
|
||||||
|
// '/categories': (context) => const MainLayout(
|
||||||
|
// currentRoute: '/categories',
|
||||||
|
// child: CategoriesScreen(),
|
||||||
|
// ),
|
||||||
|
// '/menus': (context) => const MainLayout(
|
||||||
|
// currentRoute: '/menus',
|
||||||
|
// child: MenusScreen(),
|
||||||
|
// ),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -251,7 +251,7 @@ class _TablesScreenState extends State<TablesScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
const Text(
|
const Text(
|
||||||
'Sélectionner une table',
|
'Sélectionner une table',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
|||||||
@ -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,6 +107,50 @@ 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,13 +1,14 @@
|
|||||||
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