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
@@ -433,6 +433,11 @@ class EventFormController extends ChangeNotifier {
} }
} }
Future<bool> submitAsConfirmed(BuildContext context) async {
_selectedStatus = EventStatus.confirmed;
return await submitForm(context);
}
Future<bool> deleteEvent(BuildContext context, String eventId) async { Future<bool> deleteEvent(BuildContext context, String eventId) async {
_isLoading = true; _isLoading = true;
_error = null; _error = null;
+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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isMobile = MediaQuery.of(context).size.width < 600; final isMobile = MediaQuery.of(context).size.width < 600;
@@ -158,29 +206,23 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
} }
}, },
child: Scaffold( child: Scaffold(
backgroundColor: Colors.grey.shade50,
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
isEditMode ? 'Modifier un événement' : 'Créer un événement'), isEditMode ? 'Modifier un événement' : 'Créer un événement'),
elevation: 0,
), ),
body: Center( body: SingleChildScrollView(
child: SingleChildScrollView( child: Center(
child: (isMobile child: ConstrainedBox(
? Padding( constraints: const BoxConstraints(maxWidth: 1200),
padding: const EdgeInsets.symmetric( child: Padding(
horizontal: 16, vertical: 12), padding: EdgeInsets.symmetric(
child: _buildFormContent(isMobile), horizontal: isMobile ? 16 : 32,
) vertical: 32),
: Card( child: _buildFormContent(isMobile),
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),
),
)),
), ),
), ),
), ),
@@ -197,38 +239,43 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
EventBasicInfoSection( _buildCard(
nameController: controller.nameController, title: 'Informations générales',
basePriceController: controller.basePriceController, icon: Icons.event_note,
eventTypes: controller.eventTypes, children: [
isLoadingEventTypes: controller.isLoadingEventTypes, EventBasicInfoSection(
selectedEventTypeId: controller.selectedEventTypeId, nameController: controller.nameController,
startDateTime: controller.startDateTime, basePriceController: controller.basePriceController,
endDateTime: controller.endDateTime, eventTypes: controller.eventTypes,
onEventTypeChanged: (typeId) => isLoadingEventTypes: controller.isLoadingEventTypes,
controller.onEventTypeChanged(typeId, context), selectedEventTypeId: controller.selectedEventTypeId,
onStartDateTimeChanged: controller.setStartDateTime, startDateTime: controller.startDateTime,
onEndDateTimeChanged: controller.setEndDateTime, endDateTime: controller.endDateTime,
onAnyFieldChanged: selectedOptions: controller.selectedOptions,
() {}, // Géré automatiquement par le contrôleur 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), const SizedBox(height: 24),
OptionSelectorWidget( // Section Matériel Assigné (gère sa propre carte pour inclure les boutons d'action dans le header)
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é
EventAssignedEquipmentSection( EventAssignedEquipmentSection(
assignedEquipment: controller.assignedEquipment, assignedEquipment: controller.assignedEquipment,
assignedContainers: controller.assignedContainers, assignedContainers: controller.assignedContainers,
@@ -238,50 +285,93 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
eventId: widget.event?.id, eventId: widget.event?.id,
eventTypeId: controller.selectedEventTypeId, eventTypeId: controller.selectedEventTypeId,
), ),
const SizedBox(height: 16), const SizedBox(height: 24),
EventDetailsSection( _buildCard(
descriptionController: controller.descriptionController, title: 'Détails & Logistique',
installationController: controller.installationController, icon: Icons.location_on_outlined,
disassemblyController: controller.disassemblyController, children: [
addressController: controller.addressController, EventDetailsSection(
jaugeController: controller.jaugeController, descriptionController: controller.descriptionController,
contactEmailController: controller.contactEmailController, installationController: controller.installationController,
contactPhoneController: controller.contactPhoneController, disassemblyController: controller.disassemblyController,
isMobile: isMobile, addressController: controller.addressController,
onAnyFieldChanged: jaugeController: controller.jaugeController,
() {}, // Géré automatiquement par le contrôleur contactEmailController: controller.contactEmailController,
contactPhoneController: controller.contactPhoneController,
isMobile: isMobile,
onAnyFieldChanged: () {},
),
],
), ),
EventStaffAndDocumentsSection( const SizedBox(height: 24),
allUsers: controller.allUsers, _buildCard(
selectedUserIds: controller.selectedUserIds, title: 'Personnel & Documents',
onUserSelectionChanged: controller.setSelectedUserIds, icon: Icons.group_outlined,
isLoadingUsers: controller.isLoadingUsers, children: [
uploadedFiles: controller.uploadedFiles, EventStaffAndDocumentsSection(
onFilesChanged: controller.setUploadedFiles, allUsers: controller.allUsers,
isLoading: controller.isLoading, selectedUserIds: controller.selectedUserIds,
error: controller.error, onUserSelectionChanged: controller.setSelectedUserIds,
success: controller.success, isLoadingUsers: controller.isLoadingUsers,
isMobile: isMobile, uploadedFiles: controller.uploadedFiles,
onPickAndUploadFiles: controller.pickAndUploadFiles, onFilesChanged: controller.setUploadedFiles,
isLoading: controller.isLoading,
error: controller.error,
success: controller.success,
isMobile: isMobile,
onPickAndUploadFiles: controller.pickAndUploadFiles,
),
],
), ),
if (controller.error != null) if (controller.error != null)
Padding( Padding(
padding: const EdgeInsets.only(top: 16.0), padding: const EdgeInsets.only(top: 24.0),
child: Text( child: Container(
controller.error!, padding: const EdgeInsets.all(12),
style: const TextStyle(color: Colors.red), decoration: BoxDecoration(
textAlign: TextAlign.center, 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) if (controller.success != null)
Padding( Padding(
padding: const EdgeInsets.only(top: 16.0), padding: const EdgeInsets.only(top: 24.0),
child: Text( child: Container(
controller.success!, padding: const EdgeInsets.all(12),
style: const TextStyle(color: Colors.green), decoration: BoxDecoration(
textAlign: TextAlign.center, 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( EventFormActions(
isLoading: controller.isLoading, isLoading: controller.isLoading,
isEditMode: isEditMode, isEditMode: isEditMode,
@@ -292,11 +382,15 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
} }
}, },
onSubmit: _submit, onSubmit: _submit,
onSetConfirmed: !isEditMode ? () {} : null, onSetConfirmed: !isEditMode ? () async {
onDelete: isEditMode final success = await controller.submitAsConfirmed(context);
? _deleteEvent if (success && context.mounted) {
: null, // Ajout du callback de suppression Navigator.of(context).pop();
}
} : null,
onDelete: isEditMode ? _deleteEvent : null,
), ),
const SizedBox(height: 48), // Padding bottom for scrolling
], ],
), ),
); );
@@ -262,11 +262,18 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
); );
if (confirm == true && context.mounted) { if (confirm == true && context.mounted) {
// Utiliser le rootNavigator pour s'assurer qu'on gère la bonne pile de navigation
final navigator = Navigator.of(context, rootNavigator: true);
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (BuildContext context) { useRootNavigator: true,
return const Center(child: CircularProgressIndicator()); builder: (BuildContext dialogContext) {
return const PopScope(
canPop: false,
child: Center(child: CircularProgressIndicator()),
);
}, },
); );
@@ -277,15 +284,21 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
'targetStep': selectedStep, 'targetStep': selectedStep,
}); });
// Attendre un tout petit peu pour s'assurer que le showDialog a eu le temps
// de faire son animation d'entrée si l'API a répondu trop vite.
await Future.delayed(const Duration(milliseconds: 200));
if (context.mounted) { if (context.mounted) {
final eventProvider = Provider.of<EventProvider>(context, listen: false); final eventProvider = Provider.of<EventProvider>(context, listen: false);
final userProvider = Provider.of<LocalUserProvider>(context, listen: false); final userProvider = Provider.of<LocalUserProvider>(context, listen: false);
if (userProvider.currentUser != null) { if (userProvider.currentUser != null) {
await eventProvider.refreshEvents(userProvider.currentUser!.uid); await eventProvider.refreshEvents(userProvider.currentUser!.uid);
} }
}
Navigator.of(context).pop(); // Fermer le loader navigator.pop(); // Fermer le loader
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(
content: Text('Retour en arrière effectué avec succès'), content: Text('Retour en arrière effectué avec succès'),
@@ -294,8 +307,9 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
); );
} }
} catch (e) { } catch (e) {
navigator.pop(); // Fermer le loader
if (context.mounted) { if (context.mounted) {
Navigator.of(context).pop(); // Fermer le loader
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text('Erreur : $e'), content: Text('Erreur : $e'),
@@ -43,6 +43,7 @@ class _EventAssignedEquipmentSectionState
final Map<String, EquipmentModel> _equipmentCache = {}; final Map<String, EquipmentModel> _equipmentCache = {};
final Map<String, ContainerModel> _containerCache = {}; final Map<String, ContainerModel> _containerCache = {};
bool _isLoading = true; bool _isLoading = true;
final ScrollController _scrollController = ScrollController();
@override @override
void initState() { void initState() {
@@ -50,6 +51,12 @@ class _EventAssignedEquipmentSectionState
_loadEquipmentAndContainers(); _loadEquipmentAndContainers();
} }
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override @override
void didUpdateWidget(EventAssignedEquipmentSection oldWidget) { void didUpdateWidget(EventAssignedEquipmentSection oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
@@ -394,74 +401,93 @@ class _EventAssignedEquipmentSectionState
widget.assignedEquipment.length + widget.assignedContainers.length; widget.assignedEquipment.length + widget.assignedContainers.length;
return Card( return Card(
elevation: 2, elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(16),
side: BorderSide(color: Colors.grey.shade200, width: 1),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(24),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// En-tête // En-tête
Row( SizedBox(
children: [ width: double.infinity,
Container( child: Wrap(
padding: const EdgeInsets.all(8), spacing: 16,
decoration: BoxDecoration( runSpacing: 16,
color: AppColors.rouge.withValues(alpha: 0.1), crossAxisAlignment: WrapCrossAlignment.center,
borderRadius: BorderRadius.circular(8), alignment: WrapAlignment.spaceBetween,
), children: [
child: const Icon( Row(
Icons.inventory_2, mainAxisSize: MainAxisSize.min,
color: AppColors.rouge,
size: 24,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Text( Container(
'Matériel assigné', padding: const EdgeInsets.all(10),
style: TextStyle( decoration: BoxDecoration(
fontSize: 18, color: AppColors.rouge.withOpacity(0.1),
fontWeight: FontWeight.bold, borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.inventory_2,
color: AppColors.rouge,
size: 22,
), ),
), ),
Text( const SizedBox(width: 16),
'$totalItems élément(s)', Column(
style: TextStyle( crossAxisAlignment: CrossAxisAlignment.start,
fontSize: 14, mainAxisSize: MainAxisSize.min,
color: Colors.grey.shade600, children: [
const Text(
'Matériel assigné',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
Text(
'$totalItems élément(s)',
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade600,
),
),
],
),
],
),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
ActionChip(
onPressed: _canAddMaterial ? _openAiAssistantDialog : null,
avatar: const Icon(Icons.auto_fix_high, size: 18),
label: const Text('Assistant IA'),
),
ElevatedButton.icon(
onPressed: _canAddMaterial ? _openSelectionDialog : null,
icon: Icon(Icons.add,
color: _canAddMaterial ? Colors.white : Colors.grey),
label: Text(
'Ajouter',
style: TextStyle(
color: _canAddMaterial ? Colors.white : Colors.grey),
),
style: ElevatedButton.styleFrom(
backgroundColor: _canAddMaterial
? AppColors.rouge
: Colors.grey.shade300,
), ),
), ),
], ],
), ),
), ],
ActionChip( ),
onPressed: _canAddMaterial ? _openAiAssistantDialog : null,
avatar: const Icon(Icons.auto_fix_high, size: 18),
label: const Text('Assistant IA'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
onPressed: _canAddMaterial ? _openSelectionDialog : null,
icon: Icon(Icons.add,
color: _canAddMaterial ? Colors.white : Colors.grey),
label: Text(
'Ajouter',
style: TextStyle(
color: _canAddMaterial ? Colors.white : Colors.grey),
),
style: ElevatedButton.styleFrom(
backgroundColor: _canAddMaterial
? AppColors.rouge
: Colors.grey.shade300,
),
),
],
), ),
// Message si dates non sélectionnées // Message si dates non sélectionnées
@@ -522,42 +548,83 @@ class _EventAssignedEquipmentSectionState
), ),
) )
else else
Column( Container(
crossAxisAlignment: CrossAxisAlignment.start, constraints: const BoxConstraints(maxHeight: 400),
children: [ decoration: BoxDecoration(
// Conteneurs border: Border.all(color: Colors.grey.shade200),
if (widget.assignedContainers.isNotEmpty) ...[ borderRadius: BorderRadius.circular(8),
Text( color: Colors.grey.shade50,
'Boîtes (${widget.assignedContainers.length})', ),
style: const TextStyle( child: SingleChildScrollView(
fontWeight: FontWeight.bold, controller: _scrollController,
fontSize: 16, padding: const EdgeInsets.all(12),
), child: LayoutBuilder(
), builder: (context, constraints) {
const SizedBox(height: 8), final hasContainers = widget.assignedContainers.isNotEmpty;
...widget.assignedContainers.map((containerId) { final hasEquipment = _getStandaloneEquipment().isNotEmpty;
final container = _containerCache[containerId];
return _buildContainerItem(container);
}),
const SizedBox(height: 16),
],
// Équipements directs (qui ne sont PAS dans un conteneur assigné) final containersContent = Column(
if (_getStandaloneEquipment().isNotEmpty) ...[ crossAxisAlignment: CrossAxisAlignment.start,
Text( children: [
'Équipements (${_getStandaloneEquipment().length})', if (hasContainers) ...[
style: const TextStyle( Text(
fontWeight: FontWeight.bold, 'Boîtes (${widget.assignedContainers.length})',
fontSize: 16, style: const TextStyle(
), fontWeight: FontWeight.bold,
), fontSize: 16,
const SizedBox(height: 8), ),
..._getStandaloneEquipment().map((eq) { ),
final equipment = _equipmentCache[eq.equipmentId]; const SizedBox(height: 8),
return _buildEquipmentItem(equipment, eq); ...widget.assignedContainers.map((containerId) {
}), final container = _containerCache[containerId];
], return _buildContainerItem(container);
], }),
const SizedBox(height: 16),
]
],
);
final equipmentContent = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasEquipment) ...[
Text(
'Équipements (${_getStandaloneEquipment().length})',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(height: 8),
..._getStandaloneEquipment().map((eq) {
final equipment = _equipmentCache[eq.equipmentId];
return _buildEquipmentItem(equipment, eq);
}),
]
],
);
if (constraints.maxWidth > 600 && hasContainers && hasEquipment) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: containersContent),
const SizedBox(width: 24),
Expanded(child: equipmentContent),
],
);
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
containersContent,
equipmentContent,
],
);
}
},
),
),
), ),
], ],
), ),
@@ -11,6 +11,7 @@ class EventBasicInfoSection extends StatelessWidget {
final String? selectedEventTypeId; final String? selectedEventTypeId;
final DateTime? startDateTime; final DateTime? startDateTime;
final DateTime? endDateTime; final DateTime? endDateTime;
final List<Map<String, dynamic>> selectedOptions;
final Function(String?) onEventTypeChanged; final Function(String?) onEventTypeChanged;
final Function(DateTime?) onStartDateTimeChanged; final Function(DateTime?) onStartDateTimeChanged;
final Function(DateTime?) onEndDateTimeChanged; final Function(DateTime?) onEndDateTimeChanged;
@@ -25,6 +26,7 @@ class EventBasicInfoSection extends StatelessWidget {
required this.selectedEventTypeId, required this.selectedEventTypeId,
required this.startDateTime, required this.startDateTime,
required this.endDateTime, required this.endDateTime,
required this.selectedOptions,
required this.onEventTypeChanged, required this.onEventTypeChanged,
required this.onStartDateTimeChanged, required this.onStartDateTimeChanged,
required this.onEndDateTimeChanged, required this.onEndDateTimeChanged,
@@ -36,7 +38,6 @@ class EventBasicInfoSection extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
_buildSectionTitle('Informations principales'),
TextFormField( TextFormField(
controller: nameController, controller: nameController,
decoration: const InputDecoration( decoration: const InputDecoration(
@@ -50,113 +51,104 @@ class EventBasicInfoSection extends StatelessWidget {
if (isLoadingEventTypes) if (isLoadingEventTypes)
const Center(child: CircularProgressIndicator()) const Center(child: CircularProgressIndicator())
else else
Row( DropdownButtonFormField<String>(
mainAxisSize: MainAxisSize.min, initialValue: selectedEventTypeId,
children: [ items: eventTypes
Flexible( .map((type) => DropdownMenuItem<String>(
fit: FlexFit.loose, value: type.id,
child: DropdownButtonFormField<String>( child: Text(type.name),
initialValue: selectedEventTypeId, ))
items: eventTypes .toList(),
.map((type) => DropdownMenuItem<String>( onChanged: onEventTypeChanged,
value: type.id, decoration: const InputDecoration(
child: Text(type.name), labelText: 'Type d\'événement*',
)) border: OutlineInputBorder(),
.toList(), prefixIcon: Icon(Icons.category),
onChanged: onEventTypeChanged, ),
decoration: const InputDecoration( validator: (v) => v == null ? 'Sélectionnez un type' : null,
labelText: 'Type d\'événement*',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.category),
),
validator: (v) => v == null ? 'Sélectionnez un type' : null,
),
),
const SizedBox(width: 16),
Flexible(
fit: FlexFit.loose,
child: _buildDateTimeRow(context),
),
],
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
_buildDateTimeRow(context),
const SizedBox(height: 16),
PriceHtTtcFields( PriceHtTtcFields(
basePriceController: basePriceController, basePriceController: basePriceController,
onPriceChanged: onAnyFieldChanged, onPriceChanged: onAnyFieldChanged,
selectedOptions: selectedOptions,
), ),
], ],
); );
} }
Widget _buildSectionTitle(String title) {
return Padding(
padding: const EdgeInsets.only(top: 0.0, bottom: 4.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
title,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
);
}
Widget _buildDateTimeRow(BuildContext context) { Widget _buildDateTimeRow(BuildContext context) {
return Row( final startField = GestureDetector(
children: [ onTap: () => _selectStartDateTime(context),
Expanded( child: AbsorbPointer(
child: GestureDetector( child: TextFormField(
onTap: () => _selectStartDateTime(context), readOnly: true,
child: AbsorbPointer( decoration: const InputDecoration(
child: TextFormField( labelText: 'Début*',
readOnly: true, border: OutlineInputBorder(),
decoration: const InputDecoration( suffixIcon: Icon(Icons.edit_calendar),
labelText: 'Début*',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar),
),
controller: TextEditingController(
text: startDateTime == null
? ''
: DateFormat('dd/MM/yyyy HH:mm').format(startDateTime!),
),
validator: (v) => startDateTime == null ? 'Champ requis' : null,
),
),
), ),
), controller: TextEditingController(
const SizedBox(width: 16), text: startDateTime == null
Expanded( ? ''
child: GestureDetector( : DateFormat('dd/MM/yyyy HH:mm').format(startDateTime!),
onTap: startDateTime == null ? null : () => _selectEndDateTime(context),
child: AbsorbPointer(
child: TextFormField(
readOnly: true,
decoration: const InputDecoration(
labelText: 'Fin*',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar),
),
controller: TextEditingController(
text: endDateTime == null
? ''
: DateFormat('dd/MM/yyyy HH:mm').format(endDateTime!),
),
validator: (v) => endDateTime == null
? 'Champ requis'
: (startDateTime != null &&
endDateTime != null &&
(endDateTime!.isBefore(startDateTime!) ||
endDateTime!.isAtSameMomentAs(startDateTime!)))
? 'La date de fin doit être après la date de début'
: null,
),
),
), ),
validator: (v) => startDateTime == null ? 'Champ requis' : null,
), ),
], ),
);
final endField = GestureDetector(
onTap: startDateTime == null ? null : () => _selectEndDateTime(context),
child: AbsorbPointer(
child: TextFormField(
readOnly: true,
decoration: const InputDecoration(
labelText: 'Fin*',
border: OutlineInputBorder(),
suffixIcon: Icon(Icons.edit_calendar),
),
controller: TextEditingController(
text: endDateTime == null
? ''
: DateFormat('dd/MM/yyyy HH:mm').format(endDateTime!),
),
validator: (v) => endDateTime == null
? 'Champ requis'
: (startDateTime != null &&
endDateTime != null &&
(endDateTime!.isBefore(startDateTime!) ||
endDateTime!.isAtSameMomentAs(startDateTime!)))
? 'La date de fin doit être après la date de début'
: null,
),
),
);
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth > 500) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: startField),
const SizedBox(width: 16),
Expanded(child: endField),
],
);
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
startField,
const SizedBox(height: 16),
endField,
],
);
}
},
); );
} }
@@ -56,8 +56,6 @@ class _EventDetailsSectionState extends State<EventDetailsSection> {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
_buildSectionTitle('Détails'),
// Description et champs de contact // Description et champs de contact
widget.isMobile widget.isMobile
? _buildMobileLayout() ? _buildMobileLayout()
@@ -88,7 +86,8 @@ class _EventDetailsSectionState extends State<EventDetailsSection> {
], ],
), ),
_buildSectionTitle('Adresse*'), const SizedBox(height: 20),
TextFormField( TextFormField(
controller: widget.addressController, controller: widget.addressController,
decoration: const InputDecoration( decoration: const InputDecoration(
@@ -196,17 +195,4 @@ class _EventDetailsSectionState extends State<EventDetailsSection> {
], ],
); );
} }
Widget _buildSectionTitle(String title) {
return Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 8.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
title,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
);
}
} }
@@ -20,67 +20,64 @@ class EventFormActions extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Padding(
children: [ padding: const EdgeInsets.only(top: 24.0),
const SizedBox(height: 24), child: Wrap(
Row( alignment: WrapAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: WrapCrossAlignment.center,
children: [ spacing: 16,
// Bouton de suppression en mode édition runSpacing: 16,
if (isEditMode && onDelete != null) children: [
ElevatedButton.icon( // Bouton de suppression en mode édition
icon: const Icon(Icons.delete, color: Colors.white), if (isEditMode && onDelete != null)
label: const Text('Supprimer'), ElevatedButton.icon(
style: ElevatedButton.styleFrom( icon: const Icon(Icons.delete, color: Colors.white),
backgroundColor: Colors.red, label: const Text('Supprimer'),
foregroundColor: Colors.white, style: ElevatedButton.styleFrom(
), backgroundColor: Colors.red,
onPressed: isLoading ? null : onDelete, foregroundColor: Colors.white,
)
else
const SizedBox.shrink(), // Espace vide si pas en mode édition
// Boutons Annuler et Enregistrer/Créer
Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: isLoading ? null : onCancel,
child: const Text('Annuler'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
icon: const Icon(Icons.check),
onPressed: isLoading ? null : onSubmit,
label: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(isEditMode ? 'Enregistrer' : 'Créer'),
),
],
),
],
),
if (!isEditMode && onSetConfirmed != null)
Center(
child: Padding(
padding: const EdgeInsets.only(top: 16.0),
child: ElevatedButton.icon(
icon: const Icon(Icons.check_circle, color: Colors.white),
label: const Text('Définir cet événement comme confirmé'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: onSetConfirmed,
), ),
), onPressed: isLoading ? null : onDelete,
)
else
const SizedBox.shrink(),
// Boutons Annuler, Enregistrer/Créer et Valider
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
TextButton(
onPressed: isLoading ? null : onCancel,
child: const Text('Annuler'),
),
ElevatedButton.icon(
icon: const Icon(Icons.check),
onPressed: isLoading ? null : onSubmit,
label: isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(isEditMode ? 'Enregistrer' : 'Créer'),
),
if (!isEditMode && onSetConfirmed != null)
ElevatedButton.icon(
icon: const Icon(Icons.check_circle, color: Colors.white),
label: const Text('Créer et valider'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
onPressed: isLoading ? null : onSetConfirmed,
),
],
), ),
], ],
),
); );
} }
} }
@@ -36,16 +36,22 @@ class EventStaffAndDocumentsSection extends StatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
_buildSectionTitle('Personnel'),
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded( Expanded(
child: UserMultiSelectWidget( child: Column(
allUsers: allUsers, crossAxisAlignment: CrossAxisAlignment.start,
selectedUserIds: selectedUserIds, children: [
onChanged: onUserSelectionChanged, const Text('Personnel', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
isLoading: isLoadingUsers, const SizedBox(height: 8),
UserMultiSelectWidget(
allUsers: allUsers,
selectedUserIds: selectedUserIds,
onChanged: onUserSelectionChanged,
isLoading: isLoadingUsers,
),
],
), ),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
@@ -53,7 +59,8 @@ class EventStaffAndDocumentsSection extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
_buildSectionTitle('Documents'), const Text('Documents', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 8),
if (isMobile) if (isMobile)
_buildMobileDocumentUpload() _buildMobileDocumentUpload()
else else
@@ -73,19 +80,6 @@ class EventStaffAndDocumentsSection extends StatelessWidget {
); );
} }
Widget _buildSectionTitle(String title) {
return Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 8.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
title,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
);
}
Widget _buildMobileDocumentUpload() { Widget _buildMobileDocumentUpload() {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -8,12 +8,14 @@ class PriceHtTtcFields extends StatefulWidget {
final TextEditingController basePriceController; final TextEditingController basePriceController;
final VoidCallback onPriceChanged; final VoidCallback onPriceChanged;
final double taxRate; final double taxRate;
final List<Map<String, dynamic>> selectedOptions;
const PriceHtTtcFields({ const PriceHtTtcFields({
super.key, super.key,
required this.basePriceController, required this.basePriceController,
required this.onPriceChanged, required this.onPriceChanged,
this.taxRate = 0.20, this.taxRate = 0.20,
this.selectedOptions = const [],
}); });
@override @override
@@ -133,7 +135,7 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Text( const Text(
'Prix', 'Prix Base',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
@@ -205,7 +207,7 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
], ],
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
// Affichage du montant de TVA (en plus petit) // Affichage du montant de TVA (en plus petit) et du Prix Total
Builder( Builder(
builder: (context) { builder: (context) {
final htText = _htController.text.replaceAll(',', '.'); final htText = _htController.text.replaceAll(',', '.');
@@ -213,16 +215,72 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
if (htValue != null) { if (htValue != null) {
final taxAmount = PriceHelpers.calculateTax(htValue, taxRate: widget.taxRate); final taxAmount = PriceHelpers.calculateTax(htValue, taxRate: widget.taxRate);
return Padding( final ttcValue = PriceHelpers.calculateTTC(htValue, taxRate: widget.taxRate);
padding: const EdgeInsets.only(left: 8.0, top: 4.0),
child: Text( return Column(
'TVA (${(widget.taxRate * 100).toStringAsFixed(0)}%) : ${taxAmount.toStringAsFixed(2)}', crossAxisAlignment: CrossAxisAlignment.start,
style: TextStyle( children: [
fontSize: 11, Padding(
color: Colors.grey[600], padding: const EdgeInsets.only(left: 8.0, top: 4.0),
fontStyle: FontStyle.italic, child: Text(
'TVA (${(widget.taxRate * 100).toStringAsFixed(0)}%) : ${taxAmount.toStringAsFixed(2)}',
style: TextStyle(
fontSize: 11,
color: Colors.grey[600],
fontStyle: FontStyle.italic,
),
),
), ),
), if (widget.selectedOptions.isNotEmpty) ...[
const SizedBox(height: 16),
Builder(
builder: (context) {
double optionsTotalTTC = 0.0;
for (var opt in widget.selectedOptions) {
// Les options sont stockées en TTC ou HT ?
// Généralement l'application utilise TTC.
final optPrice = opt['price'] is double ? opt['price'] : double.tryParse(opt['price'].toString()) ?? 0.0;
final optQuantity = opt['quantity'] is int ? opt['quantity'] : int.tryParse(opt['quantity'].toString()) ?? 1;
optionsTotalTTC += optPrice * optQuantity;
}
final totalTTC = ttcValue + optionsTotalTTC;
final totalHT = PriceHelpers.calculateHT(totalTTC, taxRate: widget.taxRate);
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.blue.shade100),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Prix Total (Base + Options)',
style: TextStyle(fontWeight: FontWeight.bold),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${totalHT.toStringAsFixed(2)} € HT',
style: TextStyle(fontSize: 14, color: Colors.blue.shade800),
),
Text(
'${totalTTC.toStringAsFixed(2)} € TTC',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.blue.shade900),
),
],
),
],
),
);
}
),
],
],
); );
} }
return const SizedBox.shrink(); return const SizedBox.shrink();