Skip to content
Snippets Groups Projects
Commit 0ac6796a authored by DAI Leslie's avatar DAI Leslie
Browse files

addclub et modclub design update

parent a1cf2215
No related branches found
No related tags found
No related merge requests found
import 'package:atlub/Mods/Theme_colors/colors.dart';
import 'package:atlub/Mods/forms_assets/send_button.dart';
import 'package:atlub/Mods/forms_assets/text_field.dart';
import 'package:dropdown_search/dropdown_search.dart';
import 'package:flutter/material.dart';
import 'package:atlub/Services/database.dart';
......@@ -7,7 +9,7 @@ import 'package:provider/provider.dart';
class AddClub extends StatefulWidget {
final String BDX;
const AddClub({super.key, required this.BDX});
const AddClub({Key? key, required this.BDX}) : super(key: key);
@override
State<AddClub> createState() => _AddClubState();
......@@ -20,19 +22,18 @@ class _AddClubState extends State<AddClub> {
String selectedBDXType = '';
String? selectedPrez;
String? selectedCoPrez;
List<Map<String, dynamic>> profileList = []; // Liste des profils triés
List<Map<String, dynamic>> profileList = [];
@override
void initState() {
super.initState();
selectedBDXType = widget.BDX;
loadProfiles(); // Charger les profils lors de l'initialisation de l'état
loadProfiles();
}
Future<void> loadProfiles() async {
try {
Map<String, Map<String, dynamic>> profilesData = await DatabaseService().getProfiles();
// Extraire les valeurs des profils triés pour DropdownSearch
List<Map<String, dynamic>> sortedProfiles = profilesData.values.toList();
setState(() {
profileList = sortedProfiles;
......@@ -42,6 +43,32 @@ class _AddClubState extends State<AddClub> {
}
}
Widget buildDropdown(String label, String hint, String? selectedValue, Function(Map<String, dynamic>?) onChanged) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true,
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: hint,
border: OutlineInputBorder(),
),
),
onChanged: onChanged,
validator: (selectedItem) => selectedItem == null ? 'Veuillez sélectionner un $label.' : null,
),
const SizedBox(height: 20),
],
);
}
@override
Widget build(BuildContext context) {
final userinBDX = Provider.of<UserProvider>(context).userinBDX ?? {"BDA": false, "BDS": false, "BDD": false, "BDE": false};
......@@ -56,14 +83,15 @@ class _AddClubState extends State<AddClub> {
key: _formKey,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
const Center(
child: Text(
'Ajouter un club',
style: TextStyle(color: AppColor.violetBlue, fontSize: 30, fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 30),
MyTextField(
label: 'Club',
......@@ -72,87 +100,42 @@ class _AddClubState extends State<AddClub> {
isRequired: true,
),
const SizedBox(height: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Président', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true, // Ajout de la barre de recherche
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Sélectionner le Président",
border: OutlineInputBorder(),
),
),
onChanged: (profile) {
buildDropdown('Président', 'Sélectionner le Président', selectedPrez, (profile) {
setState(() {
selectedPrez = profile?['uid'];
});
},
),
const SizedBox(height: 20),
Text('Co-président', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true, // Ajout de la barre de recherche
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Sélectionner le Co-président",
border: OutlineInputBorder(),
),
),
onChanged: (profile) {
}),
buildDropdown('Co-président', 'Sélectionner le Co-président', selectedCoPrez, (profile) {
setState(() {
selectedCoPrez = profile?['uid'];
});
},
),
],
),
const SizedBox(height: 20),
}),
MyTextField(
label: 'Description',
hint: 'Entrez la description du club',
controller: descripController,
),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(bottom: 10),
child: DropdownButtonFormField(
DropdownButtonFormField(
items: userinBDX.entries
.where((entry) => entry.value == true)
.where((entry) => entry.value)
.map((entry) => DropdownMenuItem(value: entry.key, child: Text(entry.key)))
.toList(),
decoration: const InputDecoration(border: OutlineInputBorder()),
value: selectedBDXType,
onChanged: (value) {
setState(() {
selectedBDXType = value.toString();
selectedBDXType = value as String;
});
},
),
),
const SizedBox(height: 20),
SendButton(onTap: () async {
if (_formKey.currentState!.validate()) {
final club = clubController.text;
final prez = selectedPrez;
final coprez = selectedCoPrez;
final descrip = descripController.text;
// Afficher la valeur de l'ID du président pour le débogage
print('ID du président sélectionné: $prez');
if (prez == null) {
if (selectedPrez == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Le Président est obligatoire")),
);
......@@ -160,32 +143,19 @@ class _AddClubState extends State<AddClub> {
}
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Envoyé")));
FocusScope.of(context).requestFocus(FocusNode());
_formKey.currentState!.reset();
// Attendre un court délai avant de vérifier à nouveau si le président est sélectionné
await Future.delayed(Duration(milliseconds: 100));
if (selectedPrez == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Le Président est obligatoire")),
const SnackBar(content: Text("Envoyé")),
);
return;
}
DatabaseService db = DatabaseService();
FocusScope.of(context).unfocus();
try {
final idclub = await db.addclub(selectedBDXType, club, descrip);
final idclub = await DatabaseService().addclub(selectedBDXType, club, descrip);
if (prez != null) {
await db.addPresident(prez, idclub, "current");
if (selectedPrez != null) {
await DatabaseService().addPresident(selectedPrez!, idclub, "current");
}
if (coprez != null && coprez.isNotEmpty) {
await db.addPresident(coprez, idclub, "co");
if (selectedCoPrez != null && selectedCoPrez!.isNotEmpty) {
await DatabaseService().addPresident(selectedCoPrez!, idclub, "co");
}
Navigator.pop(context);
......@@ -194,62 +164,11 @@ class _AddClubState extends State<AddClub> {
}
}
}),
],
),
),
),
),
),
);
}
}
class MyTextField extends StatelessWidget {
final String label;
final String hint;
final TextEditingController controller;
final bool isRequired;
const MyTextField({
required this.label,
required this.hint,
required this.controller,
this.isRequired = false,
});
@override
Widget build(BuildContext context) {
return TextFormField(
controller: controller,
decoration: InputDecoration(
labelText: label,
hintText: hint,
border: OutlineInputBorder(),
),
validator: (value) {
if (isRequired && (value == null || value.isEmpty)) {
return 'Champ requis';
}
return null;
},
);
}
}
class SendButton extends StatelessWidget {
final VoidCallback onTap;
const SendButton({required this.onTap});
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onTap,
child: Text("Envoyer"),
);
}
}
......@@ -23,7 +23,7 @@ class _ModClubState extends State<ModClub> {
String? selectedPrez;
String? selectedCoPrez;
late String selectedBDXType;
List<Map<String, dynamic>> profileList = []; // Liste des profils triés
List<Map<String, dynamic>> profileList = [];
@override
void initState() {
......@@ -31,36 +31,58 @@ class _ModClubState extends State<ModClub> {
database = DatabaseService();
clubController = TextEditingController();
descripController = TextEditingController();
selectedBDXType = 'BDE'; // Initialisez selectedBDXType avec une valeur par défaut
selectedBDXType = 'BDE';
getInitialData();
loadProfiles();
}
Future<void> loadProfiles() async {
Future<void> getInitialData() async {
try {
Map<String, Map<String, dynamic>> profilesData = await DatabaseService().getProfiles();
// Extraire les valeurs des profils triés pour DropdownSearch
List<Map<String, dynamic>> sortedProfiles = profilesData.values.toList();
final initialData = await Future.wait([
database.getClubNom(widget.idClub),
database.getPresidentClubnom(widget.idClub, "current"),
database.getPresidentClubnom(widget.idClub, "co"),
database.getClubBDX(widget.idClub),
database.getClubDescription(widget.idClub),
database.getProfiles()
]);
setState(() {
profileList = sortedProfiles;
clubController.text = initialData[0] as String;
selectedPrez = initialData[1] as String?;
selectedCoPrez = initialData[2] as String?;
selectedBDXType = initialData[3] as String;
descripController.text = initialData[4] as String;
profileList = (initialData[5] as Map<String, Map<String, dynamic>>).values.toList();
});
} catch (error) {
print("Erreur lors du chargement des profils : $error");
print('Erreur lors de la récupération des données initiales du club: $error');
}
}
void getInitialData() async {
try {
clubController.text = await database.getClubNom(widget.idClub);
selectedPrez = (await database.getPresidentClubnom(widget.idClub, "current"))!;
selectedCoPrez = (await database.getPresidentClubnom(widget.idClub, "co"))!;
selectedBDXType = await database.getClubBDX(widget.idClub);
descripController.text = await database.getClubDescription(widget.idClub); // Initialisez le champ de description avec la valeur de la base de données
setState(() {});
} catch (error) {
print('Erreur lors de la récupération des données initiales du club: $error');
}
Widget buildDropdown(String label, String hint, String? selectedValue, Function(Map<String, dynamic>?) onChanged) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true,
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: hint,
border: OutlineInputBorder(),
),
),
onChanged: onChanged,
validator: (selectedItem) => selectedItem == null ? 'Veuillez sélectionner un $label.' : null,
),
const SizedBox(height: 20),
],
);
}
@override
......@@ -77,77 +99,32 @@ class _ModClubState extends State<ModClub> {
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
const Text('Modifier le club', style: TextStyle(color: AppColor.violetBlue, fontSize: 30, fontWeight: FontWeight.bold),),
const SizedBox(height: 30,),
const Text('Modifier le club', style: TextStyle(color: AppColor.violetBlue, fontSize: 30, fontWeight: FontWeight.bold)),
const SizedBox(height: 30),
MyTextField(label: 'Club', hint: 'Entrez le nom du club', controller: clubController, isRequired: true),
const SizedBox(height: 20,),
// Ajoutez la liste déroulante pour le Président ici
Text('Président', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true, // Ajout de la barre de recherche
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Sélectionner le Président",
border: OutlineInputBorder(),
),
),
onChanged: (profile) {
const SizedBox(height: 20),
buildDropdown('Président', 'Sélectionner le Président', selectedPrez, (profile) {
setState(() {
selectedPrez = profile?['uid'];
});
},
validator: (selectedItem) {
if (selectedItem == null) {
return 'Veuillez sélectionner un président.';
}
return null;
},
),
const SizedBox(height: 20,),
// Ajoutez la liste déroulante pour le Co-Président ici
Text('Co-président', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownSearch<Map<String, dynamic>>(
popupProps: PopupProps.menu(
showSelectedItems: false,
showSearchBox: true, // Ajout de la barre de recherche
),
items: profileList,
itemAsString: (profile) => '${profile['nom']} ${profile['prenom']}',
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Sélectionner le Co-président",
border: OutlineInputBorder(),
),
),
onChanged: (profile) {
}),
buildDropdown('Co-président', 'Sélectionner le Co-président', selectedCoPrez, (profile) {
setState(() {
selectedCoPrez = profile?['uid'];
});
},
),
const SizedBox(height: 20,),
}),
MyTextField(label: 'Description', hint: "Entrez la description", controller: descripController),
const SizedBox(height: 20,),
const SizedBox(height: 20),
Container(
margin: const EdgeInsets.only(bottom: 10),
child: DropdownButtonFormField(
items: const [
DropdownMenuItem(
value: 'BDE', child: Text("BDE")),
DropdownMenuItem(
value: 'BDA', child: Text("BDA")),
DropdownMenuItem(
value: 'BDS', child: Text("BDS")),
DropdownMenuItem(
value: 'BDD', child: Text("BDD")),
DropdownMenuItem(value: 'BDE', child: Text("BDE")),
DropdownMenuItem(value: 'BDA', child: Text("BDA")),
DropdownMenuItem(value: 'BDS', child: Text("BDS")),
DropdownMenuItem(value: 'BDD', child: Text("BDD")),
],
decoration: const InputDecoration(
border: OutlineInputBorder()),
decoration: const InputDecoration(border: OutlineInputBorder()),
value: selectedBDXType,
onChanged: (value) {
setState(() {
......@@ -156,52 +133,34 @@ class _ModClubState extends State<ModClub> {
},
),
),
const SizedBox(height: 20,),
const SizedBox(height: 20),
SendButton(onTap: () async {
if (_formKey.currentState!.validate()) {
final club = clubController.text;
final descrip = descripController.text;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Envoyé")));
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Envoyé")));
FocusScope.of(context).requestFocus(FocusNode());
print("club : $club");
print("prez : $selectedPrez");
print("co-prez : $selectedCoPrez");
print("BDX : $selectedBDXType");
print("description : $descrip");
_formKey.currentState!.reset();
try {
if (selectedPrez != null) {
// Ajouter le président "current"
await database.modifierPresident(selectedPrez!, widget.idClub, "current");
} else {
print("L'ID du président est null.");
}
if (selectedCoPrez != null) {
// Ensuite, ajouter le président "co"
await database.modifierPresident(selectedCoPrez!, widget.idClub, "co");
} else {
print("L'ID du co-président est null.");
}
database.updateclub(widget.idClub, selectedBDXType, club, descrip);
// Ca c'est bien ajouté si le président existe et que le club n'est pas vide
await database.updateclub(widget.idClub, selectedBDXType, club, descrip);
if (selectedPrez != null && club.isNotEmpty) {
Navigator.pop(context);
print("page suivante : $selectedPrez, $club");
}
} catch (error) {
// Gérer les erreurs potentielles lors de la mise à jour du club ou de l'ajout des présidents
print("Une erreur s'est produite : $error");
}
}
},)
})
],
),
),
......
......@@ -383,10 +383,10 @@ packages:
dependency: "direct main"
description:
name: flutter_quill
sha256: da6f19abda6662dd3a4da7e16f17492e3205b20d09f68ffd8c0b19ec0688a343
sha256: f5c56ca799bc80fd30ff2a279f6990df2af3aef398083ec8676a04ac89c2eb05
url: "https://pub.dev"
source: hosted
version: "9.3.19"
version: "9.3.11"
flutter_svg:
dependency: "direct main"
description:
......@@ -465,10 +465,10 @@ packages:
dependency: "direct main"
description:
name: intl
sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
url: "https://pub.dev"
source: hosted
version: "0.19.0"
version: "0.18.1"
irondash_engine_context:
dependency: transitive
description:
......@@ -489,26 +489,26 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "3.0.3"
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "2.0.1"
lints:
dependency: transitive
description:
......@@ -553,10 +553,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.12.0"
version: "1.11.0"
navigator:
dependency: "direct main"
description:
......@@ -894,10 +894,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
......@@ -1030,10 +1030,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "13.0.0"
web:
dependency: transitive
description:
......
......@@ -52,7 +52,7 @@ dependencies:
grouped_list: ^4.2.0
dotted_border: ^2.1.0
intl: ^0.19.0
intl: ^0.18.1
google_fonts:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment