feat: implement event creation flow and management widgets with preparation tracking buttons

This commit is contained in:
ElPoyo
2026-05-27 23:50:02 +02:00
parent faff06e4df
commit d9cd251bb7
9 changed files with 588 additions and 381 deletions
+182 -88
View File
@@ -142,6 +142,54 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
}
}
Widget _buildCard({
required String title,
required IconData icon,
required List<Widget> children,
}) {
return Card(
elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: Colors.grey.shade200, width: 1),
),
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFFD32F2F).withOpacity(0.1), // AppColors.rouge
borderRadius: BorderRadius.circular(10),
),
child: Icon(icon, color: const Color(0xFFD32F2F), size: 22),
),
const SizedBox(width: 16),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
),
],
),
const SizedBox(height: 24),
...children,
],
),
),
);
}
@override
Widget build(BuildContext context) {
final isMobile = MediaQuery.of(context).size.width < 600;
@@ -158,29 +206,23 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
}
},
child: Scaffold(
backgroundColor: Colors.grey.shade50,
appBar: AppBar(
title: Text(
isEditMode ? 'Modifier un événement' : 'Créer un événement'),
elevation: 0,
),
body: Center(
child: SingleChildScrollView(
child: (isMobile
? Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 12),
child: _buildFormContent(isMobile),
)
: Card(
elevation: 6,
margin: const EdgeInsets.all(24),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18)),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 32, vertical: 32),
child: _buildFormContent(isMobile),
),
)),
body: SingleChildScrollView(
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1200),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: isMobile ? 16 : 32,
vertical: 32),
child: _buildFormContent(isMobile),
),
),
),
),
),
@@ -197,38 +239,43 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
EventBasicInfoSection(
nameController: controller.nameController,
basePriceController: controller.basePriceController,
eventTypes: controller.eventTypes,
isLoadingEventTypes: controller.isLoadingEventTypes,
selectedEventTypeId: controller.selectedEventTypeId,
startDateTime: controller.startDateTime,
endDateTime: controller.endDateTime,
onEventTypeChanged: (typeId) =>
controller.onEventTypeChanged(typeId, context),
onStartDateTimeChanged: controller.setStartDateTime,
onEndDateTimeChanged: controller.setEndDateTime,
onAnyFieldChanged:
() {}, // Géré automatiquement par le contrôleur
_buildCard(
title: 'Informations générales',
icon: Icons.event_note,
children: [
EventBasicInfoSection(
nameController: controller.nameController,
basePriceController: controller.basePriceController,
eventTypes: controller.eventTypes,
isLoadingEventTypes: controller.isLoadingEventTypes,
selectedEventTypeId: controller.selectedEventTypeId,
startDateTime: controller.startDateTime,
endDateTime: controller.endDateTime,
selectedOptions: controller.selectedOptions,
onEventTypeChanged: (typeId) =>
controller.onEventTypeChanged(typeId, context),
onStartDateTimeChanged: controller.setStartDateTime,
onEndDateTimeChanged: controller.setEndDateTime,
onAnyFieldChanged: () {},
),
const SizedBox(height: 16),
OptionSelectorWidget(
eventType: controller.selectedEventTypeId,
selectedOptions: controller.selectedOptions,
onChanged: controller.setSelectedOptions,
onRemove: (optionId) {
final newOptions = List<Map<String, dynamic>>.from(
controller.selectedOptions);
newOptions.removeWhere((o) => o['id'] == optionId);
controller.setSelectedOptions(newOptions);
},
eventTypeRequired: controller.selectedEventTypeId == null,
isMobile: isMobile,
),
],
),
const SizedBox(height: 16),
OptionSelectorWidget(
eventType: controller
.selectedEventTypeId, // Utilise l'ID au lieu du nom
selectedOptions: controller.selectedOptions,
onChanged: controller.setSelectedOptions,
onRemove: (optionId) {
final newOptions = List<Map<String, dynamic>>.from(
controller.selectedOptions);
newOptions.removeWhere((o) => o['id'] == optionId);
controller.setSelectedOptions(newOptions);
},
eventTypeRequired: controller.selectedEventTypeId == null,
isMobile: isMobile,
),
const SizedBox(height: 16),
// Section Matériel Assigné
const SizedBox(height: 24),
// Section Matériel Assigné (gère sa propre carte pour inclure les boutons d'action dans le header)
EventAssignedEquipmentSection(
assignedEquipment: controller.assignedEquipment,
assignedContainers: controller.assignedContainers,
@@ -238,50 +285,93 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
eventId: widget.event?.id,
eventTypeId: controller.selectedEventTypeId,
),
const SizedBox(height: 16),
EventDetailsSection(
descriptionController: controller.descriptionController,
installationController: controller.installationController,
disassemblyController: controller.disassemblyController,
addressController: controller.addressController,
jaugeController: controller.jaugeController,
contactEmailController: controller.contactEmailController,
contactPhoneController: controller.contactPhoneController,
isMobile: isMobile,
onAnyFieldChanged:
() {}, // Géré automatiquement par le contrôleur
const SizedBox(height: 24),
_buildCard(
title: 'Détails & Logistique',
icon: Icons.location_on_outlined,
children: [
EventDetailsSection(
descriptionController: controller.descriptionController,
installationController: controller.installationController,
disassemblyController: controller.disassemblyController,
addressController: controller.addressController,
jaugeController: controller.jaugeController,
contactEmailController: controller.contactEmailController,
contactPhoneController: controller.contactPhoneController,
isMobile: isMobile,
onAnyFieldChanged: () {},
),
],
),
EventStaffAndDocumentsSection(
allUsers: controller.allUsers,
selectedUserIds: controller.selectedUserIds,
onUserSelectionChanged: controller.setSelectedUserIds,
isLoadingUsers: controller.isLoadingUsers,
uploadedFiles: controller.uploadedFiles,
onFilesChanged: controller.setUploadedFiles,
isLoading: controller.isLoading,
error: controller.error,
success: controller.success,
isMobile: isMobile,
onPickAndUploadFiles: controller.pickAndUploadFiles,
const SizedBox(height: 24),
_buildCard(
title: 'Personnel & Documents',
icon: Icons.group_outlined,
children: [
EventStaffAndDocumentsSection(
allUsers: controller.allUsers,
selectedUserIds: controller.selectedUserIds,
onUserSelectionChanged: controller.setSelectedUserIds,
isLoadingUsers: controller.isLoadingUsers,
uploadedFiles: controller.uploadedFiles,
onFilesChanged: controller.setUploadedFiles,
isLoading: controller.isLoading,
error: controller.error,
success: controller.success,
isMobile: isMobile,
onPickAndUploadFiles: controller.pickAndUploadFiles,
),
],
),
if (controller.error != null)
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text(
controller.error!,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
padding: const EdgeInsets.only(top: 24.0),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.red.shade200)
),
child: Row(
children: [
Icon(Icons.error_outline, color: Colors.red.shade700),
const SizedBox(width: 12),
Expanded(
child: Text(
controller.error!,
style: TextStyle(color: Colors.red.shade700),
),
),
],
),
),
),
if (controller.success != null)
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: Text(
controller.success!,
style: const TextStyle(color: Colors.green),
textAlign: TextAlign.center,
padding: const EdgeInsets.only(top: 24.0),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.green.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.green.shade200)
),
child: Row(
children: [
Icon(Icons.check_circle_outline, color: Colors.green.shade700),
const SizedBox(width: 12),
Expanded(
child: Text(
controller.success!,
style: TextStyle(color: Colors.green.shade700),
),
),
],
),
),
),
const SizedBox(height: 24),
EventFormActions(
isLoading: controller.isLoading,
isEditMode: isEditMode,
@@ -292,11 +382,15 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
}
},
onSubmit: _submit,
onSetConfirmed: !isEditMode ? () {} : null,
onDelete: isEditMode
? _deleteEvent
: null, // Ajout du callback de suppression
onSetConfirmed: !isEditMode ? () async {
final success = await controller.submitAsConfirmed(context);
if (success && context.mounted) {
Navigator.of(context).pop();
}
} : null,
onDelete: isEditMode ? _deleteEvent : null,
),
const SizedBox(height: 48), // Padding bottom for scrolling
],
),
);