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.
302 lines
10 KiB
302 lines
10 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:youmazgestion/Views/HandleProduct.dart';
|
|
import 'package:youmazgestion/Views/RoleListPage.dart';
|
|
import 'package:youmazgestion/Views/commandManagement.dart';
|
|
import 'package:youmazgestion/Views/historique.dart';
|
|
import 'package:youmazgestion/Views/bilanMois.dart';
|
|
import 'package:youmazgestion/Views/gestionStock.dart';
|
|
import 'package:youmazgestion/Views/listUser.dart';
|
|
import 'package:youmazgestion/Views/loginPage.dart';
|
|
import 'package:youmazgestion/Views/newCommand.dart';
|
|
import 'package:youmazgestion/Views/registrationPage.dart';
|
|
import 'package:youmazgestion/accueil.dart';
|
|
import 'package:youmazgestion/controller/userController.dart';
|
|
|
|
class CustomDrawer extends StatelessWidget {
|
|
final UserController userController = Get.find<UserController>();
|
|
|
|
Future<void> clearUserData() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove('username');
|
|
await prefs.remove('role');
|
|
}
|
|
|
|
CustomDrawer({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Drawer(
|
|
backgroundColor: Colors.white,
|
|
child: ListView(
|
|
padding: EdgeInsets.zero,
|
|
children: [
|
|
// Header avec informations utilisateur
|
|
GetBuilder<UserController>(
|
|
builder: (controller) => Container(
|
|
padding: const EdgeInsets.only(top: 50, left: 20, bottom: 20),
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [Color.fromARGB(255, 4, 54, 95), Colors.blue],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const CircleAvatar(
|
|
radius: 30,
|
|
backgroundImage: AssetImage("assets/youmaz2.png"),
|
|
),
|
|
const SizedBox(width: 15),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
controller.name,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
controller.email,
|
|
style: const TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
Text(
|
|
controller.role,
|
|
style: const TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// Section Accueil
|
|
_buildDrawerItem(
|
|
icon: Icons.home,
|
|
title: "Accueil",
|
|
color: Colors.blue,
|
|
permissionAction: 'view',
|
|
permissionRoute: '/accueil',
|
|
onTap: () => Get.to(const AccueilPage()),
|
|
),
|
|
|
|
// Section Utilisateurs
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 20, top: 15, bottom: 5),
|
|
child: Text(
|
|
"GESTION UTILISATEURS",
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.person_add,
|
|
title: "Ajouter un utilisateur",
|
|
color: Colors.green,
|
|
permissionAction: 'create',
|
|
permissionRoute: '/ajouter-utilisateur',
|
|
onTap: () => Get.to(const RegistrationPage()),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.supervised_user_circle,
|
|
title: "Gérer les utilisateurs",
|
|
color: Color.fromARGB(255, 4, 54, 95),
|
|
permissionAction: 'update',
|
|
permissionRoute: '/modifier-utilisateur',
|
|
onTap: () => Get.to(const ListUserPage()),
|
|
),
|
|
|
|
// Section Produits
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 20, top: 15, bottom: 5),
|
|
child: Text(
|
|
"GESTION PRODUITS",
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.inventory,
|
|
title: "Gestion des produits",
|
|
color: Colors.indigoAccent,
|
|
permissionAction: 'create',
|
|
permissionRoute: '/ajouter-produit',
|
|
onTap: () => Get.to(const ProductManagementPage()),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.storage,
|
|
title: "Gestion de stock",
|
|
color: Colors.blueAccent,
|
|
permissionAction: 'update',
|
|
permissionRoute: '/gestion-stock',
|
|
onTap: () => Get.to(const GestionStockPage()),
|
|
),
|
|
|
|
// Section Commandes
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 20, top: 15, bottom: 5),
|
|
child: Text(
|
|
"GESTION COMMANDES",
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.add_shopping_cart,
|
|
title: "Nouvelle commande",
|
|
color: Colors.orange,
|
|
permissionAction: 'create',
|
|
permissionRoute: '/nouvelle-commande',
|
|
onTap: () => Get.to(const NouvelleCommandePage()),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.list_alt,
|
|
title: "Gérer les commandes",
|
|
color: Colors.deepPurple,
|
|
permissionAction: 'manage',
|
|
permissionRoute: '/gerer-commandes',
|
|
onTap: () => Get.to(const GestionCommandesPage()),
|
|
),
|
|
|
|
// Section Rapports
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 20, top: 15, bottom: 5),
|
|
child: Text(
|
|
"RAPPORTS",
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.bar_chart,
|
|
title: "Bilan mensuel",
|
|
color: Colors.teal,
|
|
permissionAction: 'read',
|
|
permissionRoute: '/bilan',
|
|
onTap: () => Get.to(const BilanMois()),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.history,
|
|
title: "Historique",
|
|
color: Colors.blue,
|
|
permissionAction: 'read',
|
|
permissionRoute: '/historique',
|
|
onTap: () => Get.to(HistoryPage()),
|
|
),
|
|
|
|
// Section Administration
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 20, top: 15, bottom: 5),
|
|
child: Text(
|
|
"ADMINISTRATION",
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
_buildDrawerItem(
|
|
icon: Icons.admin_panel_settings,
|
|
title: "Gérer les rôles",
|
|
color: Colors.redAccent,
|
|
permissionAction: 'admin',
|
|
permissionRoute: '/gerer-roles',
|
|
onTap: () => Get.to(const RoleListPage()),
|
|
),
|
|
|
|
// Déconnexion
|
|
const Divider(),
|
|
_buildDrawerItem(
|
|
icon: Icons.logout,
|
|
title: "Déconnexion",
|
|
color: Colors.red,
|
|
onTap: () {
|
|
Get.defaultDialog(
|
|
title: "Déconnexion",
|
|
content: const Text("Voulez-vous vraiment vous déconnecter ?"),
|
|
actions: [
|
|
TextButton(
|
|
child: const Text("Non"),
|
|
onPressed: () => Get.back(),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.red,
|
|
),
|
|
child: const Text("Oui"),
|
|
onPressed: () {
|
|
clearUserData();
|
|
Get.offAll(const LoginPage());
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDrawerItem({
|
|
required IconData icon,
|
|
required String title,
|
|
required Color color,
|
|
String? permissionAction,
|
|
String? permissionRoute,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return ListTile(
|
|
leading: Icon(icon, color: color),
|
|
title: Text(title),
|
|
trailing: permissionAction != null
|
|
? const Icon(Icons.chevron_right, color: Colors.grey)
|
|
: null,
|
|
onTap: () async {
|
|
if (permissionAction != null && permissionRoute != null) {
|
|
bool hasPermission = await userController.hasPermission(permissionAction, permissionRoute);
|
|
if (hasPermission) {
|
|
onTap();
|
|
} else {
|
|
Get.snackbar(
|
|
"Accès refusé",
|
|
"Vous n'avez pas les droits pour accéder à cette page",
|
|
backgroundColor: Colors.red,
|
|
colorText: Colors.white,
|
|
icon: const Icon(Icons.error),
|
|
duration: const Duration(seconds: 3),
|
|
snackPosition: SnackPosition.TOP,
|
|
);
|
|
}
|
|
} else {
|
|
onTap();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|