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.
126 lines
4.3 KiB
126 lines
4.3 KiB
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:youmazgestion/Models/users.dart';
|
|
import 'package:youmazgestion/Services/stock_managementDatabase.dart';
|
|
import '../Components/app_bar.dart';
|
|
//import '../Services/app_database.dart';
|
|
import 'editUser.dart';
|
|
|
|
class ListUserPage extends StatefulWidget {
|
|
const ListUserPage({super.key});
|
|
|
|
@override
|
|
_ListUserPageState createState() => _ListUserPageState();
|
|
}
|
|
|
|
class _ListUserPageState extends State<ListUserPage> {
|
|
List<Users> userList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getUsersFromDatabase();
|
|
}
|
|
|
|
Future<void> getUsersFromDatabase() async {
|
|
try {
|
|
List<Users> users = await AppDatabase.instance.getAllUsers();
|
|
setState(() {
|
|
userList = users;
|
|
});
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: CustomAppBar(title: 'Liste des utilisateurs'),
|
|
body: ListView.builder(
|
|
itemCount: userList.length,
|
|
itemBuilder: (context, index) {
|
|
Users user = userList[index];
|
|
return Card(
|
|
elevation: 3,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
shadowColor: Colors.deepOrange,
|
|
borderOnForeground: true,
|
|
child: ListTile(
|
|
title: Text(
|
|
"${user.name} ${user.lastName}",
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const SizedBox(height: 4),
|
|
Text("Username: ${user.username}"),
|
|
const SizedBox(height: 4),
|
|
Text("Privilège: ${user.role}"),
|
|
],
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.delete),
|
|
color: Colors.red,
|
|
onPressed: () {
|
|
// Action de suppression
|
|
// Vous pouvez appeler une méthode de suppression appropriée ici
|
|
// confirmation de suppression
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: const Text("Supprimer"),
|
|
content: const Text(
|
|
"Êtes-vous sûr de vouloir supprimer cet utilisateur?"),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: const Text("Annuler"),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
await AppDatabase.instance
|
|
.deleteUser(user.id!);
|
|
Navigator.of(context).pop();
|
|
setState(() {
|
|
userList.removeAt(index);
|
|
});
|
|
},
|
|
child: const Text("Supprimer"),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.edit),
|
|
color: Colors.blue,
|
|
onPressed: () {
|
|
// Action de modification
|
|
// Vous pouvez naviguer vers la page de modification avec les détails de l'utilisateur
|
|
// en utilisant Navigator.push ou showDialog, selon votre besoin
|
|
Get.to(() => EditUserPage(user: user));
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|