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;
+129 -35
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(
horizontal: 16, vertical: 12),
child: _buildFormContent(isMobile),
)
: Card(
elevation: 6,
margin: const EdgeInsets.all(24),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18)),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
horizontal: 32, vertical: 32), horizontal: isMobile ? 16 : 32,
vertical: 32),
child: _buildFormContent(isMobile), child: _buildFormContent(isMobile),
), ),
)), ),
), ),
), ),
), ),
@@ -196,6 +238,10 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildCard(
title: 'Informations générales',
icon: Icons.event_note,
children: [ children: [
EventBasicInfoSection( EventBasicInfoSection(
nameController: controller.nameController, nameController: controller.nameController,
@@ -205,17 +251,16 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
selectedEventTypeId: controller.selectedEventTypeId, selectedEventTypeId: controller.selectedEventTypeId,
startDateTime: controller.startDateTime, startDateTime: controller.startDateTime,
endDateTime: controller.endDateTime, endDateTime: controller.endDateTime,
selectedOptions: controller.selectedOptions,
onEventTypeChanged: (typeId) => onEventTypeChanged: (typeId) =>
controller.onEventTypeChanged(typeId, context), controller.onEventTypeChanged(typeId, context),
onStartDateTimeChanged: controller.setStartDateTime, onStartDateTimeChanged: controller.setStartDateTime,
onEndDateTimeChanged: controller.setEndDateTime, onEndDateTimeChanged: controller.setEndDateTime,
onAnyFieldChanged: onAnyFieldChanged: () {},
() {}, // Géré automatiquement par le contrôleur
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
OptionSelectorWidget( OptionSelectorWidget(
eventType: controller eventType: controller.selectedEventTypeId,
.selectedEventTypeId, // Utilise l'ID au lieu du nom
selectedOptions: controller.selectedOptions, selectedOptions: controller.selectedOptions,
onChanged: controller.setSelectedOptions, onChanged: controller.setSelectedOptions,
onRemove: (optionId) { onRemove: (optionId) {
@@ -227,8 +272,10 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
eventTypeRequired: controller.selectedEventTypeId == null, eventTypeRequired: controller.selectedEventTypeId == null,
isMobile: isMobile, 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( EventAssignedEquipmentSection(
assignedEquipment: controller.assignedEquipment, assignedEquipment: controller.assignedEquipment,
assignedContainers: controller.assignedContainers, assignedContainers: controller.assignedContainers,
@@ -238,7 +285,11 @@ 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),
_buildCard(
title: 'Détails & Logistique',
icon: Icons.location_on_outlined,
children: [
EventDetailsSection( EventDetailsSection(
descriptionController: controller.descriptionController, descriptionController: controller.descriptionController,
installationController: controller.installationController, installationController: controller.installationController,
@@ -248,9 +299,15 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
contactEmailController: controller.contactEmailController, contactEmailController: controller.contactEmailController,
contactPhoneController: controller.contactPhoneController, contactPhoneController: controller.contactPhoneController,
isMobile: isMobile, isMobile: isMobile,
onAnyFieldChanged: onAnyFieldChanged: () {},
() {}, // Géré automatiquement par le contrôleur
), ),
],
),
const SizedBox(height: 24),
_buildCard(
title: 'Personnel & Documents',
icon: Icons.group_outlined,
children: [
EventStaffAndDocumentsSection( EventStaffAndDocumentsSection(
allUsers: controller.allUsers, allUsers: controller.allUsers,
selectedUserIds: controller.selectedUserIds, selectedUserIds: controller.selectedUserIds,
@@ -264,24 +321,57 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
isMobile: isMobile, isMobile: isMobile,
onPickAndUploadFiles: controller.pickAndUploadFiles, 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: 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( child: Text(
controller.error!, controller.error!,
style: const TextStyle(color: Colors.red), style: TextStyle(color: Colors.red.shade700),
textAlign: TextAlign.center, ),
),
],
),
), ),
), ),
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: 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( child: Text(
controller.success!, controller.success!,
style: const TextStyle(color: Colors.green), style: TextStyle(color: Colors.green.shade700),
textAlign: TextAlign.center,
), ),
), ),
],
),
),
),
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,40 +401,52 @@ 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
SizedBox(
width: double.infinity,
child: Wrap(
spacing: 16,
runSpacing: 16,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.spaceBetween,
children: [
Row( Row(
mainAxisSize: MainAxisSize.min,
children: [ children: [
Container( Container(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(10),
decoration: BoxDecoration( decoration: BoxDecoration(
color: AppColors.rouge.withValues(alpha: 0.1), color: AppColors.rouge.withOpacity(0.1),
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(10),
), ),
child: const Icon( child: const Icon(
Icons.inventory_2, Icons.inventory_2,
color: AppColors.rouge, color: AppColors.rouge,
size: 24, size: 22,
), ),
), ),
const SizedBox(width: 12), const SizedBox(width: 16),
Expanded( Column(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [ children: [
const Text( const Text(
'Matériel assigné', 'Matériel assigné',
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: Colors.black87,
), ),
), ),
Text( Text(
@@ -439,13 +458,17 @@ class _EventAssignedEquipmentSectionState
), ),
], ],
), ),
],
), ),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
ActionChip( ActionChip(
onPressed: _canAddMaterial ? _openAiAssistantDialog : null, onPressed: _canAddMaterial ? _openAiAssistantDialog : null,
avatar: const Icon(Icons.auto_fix_high, size: 18), avatar: const Icon(Icons.auto_fix_high, size: 18),
label: const Text('Assistant IA'), label: const Text('Assistant IA'),
), ),
const SizedBox(width: 8),
ElevatedButton.icon( ElevatedButton.icon(
onPressed: _canAddMaterial ? _openSelectionDialog : null, onPressed: _canAddMaterial ? _openSelectionDialog : null,
icon: Icon(Icons.add, icon: Icon(Icons.add,
@@ -463,6 +486,9 @@ class _EventAssignedEquipmentSectionState
), ),
], ],
), ),
],
),
),
// Message si dates non sélectionnées // Message si dates non sélectionnées
if (!_canAddMaterial) if (!_canAddMaterial)
@@ -522,11 +548,25 @@ class _EventAssignedEquipmentSectionState
), ),
) )
else else
Column( Container(
constraints: const BoxConstraints(maxHeight: 400),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade200),
borderRadius: BorderRadius.circular(8),
color: Colors.grey.shade50,
),
child: SingleChildScrollView(
controller: _scrollController,
padding: const EdgeInsets.all(12),
child: LayoutBuilder(
builder: (context, constraints) {
final hasContainers = widget.assignedContainers.isNotEmpty;
final hasEquipment = _getStandaloneEquipment().isNotEmpty;
final containersContent = Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Conteneurs if (hasContainers) ...[
if (widget.assignedContainers.isNotEmpty) ...[
Text( Text(
'Boîtes (${widget.assignedContainers.length})', 'Boîtes (${widget.assignedContainers.length})',
style: const TextStyle( style: const TextStyle(
@@ -540,10 +580,14 @@ class _EventAssignedEquipmentSectionState
return _buildContainerItem(container); return _buildContainerItem(container);
}), }),
const SizedBox(height: 16), const SizedBox(height: 16),
]
], ],
);
// Équipements directs (qui ne sont PAS dans un conteneur assigné) final equipmentContent = Column(
if (_getStandaloneEquipment().isNotEmpty) ...[ crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasEquipment) ...[
Text( Text(
'Équipements (${_getStandaloneEquipment().length})', 'Équipements (${_getStandaloneEquipment().length})',
style: const TextStyle( style: const TextStyle(
@@ -556,8 +600,31 @@ class _EventAssignedEquipmentSectionState
final equipment = _equipmentCache[eq.equipmentId]; final equipment = _equipmentCache[eq.equipmentId];
return _buildEquipmentItem(equipment, eq); 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,12 +51,7 @@ class EventBasicInfoSection extends StatelessWidget {
if (isLoadingEventTypes) if (isLoadingEventTypes)
const Center(child: CircularProgressIndicator()) const Center(child: CircularProgressIndicator())
else else
Row( DropdownButtonFormField<String>(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
fit: FlexFit.loose,
child: DropdownButtonFormField<String>(
initialValue: selectedEventTypeId, initialValue: selectedEventTypeId,
items: eventTypes items: eventTypes
.map((type) => DropdownMenuItem<String>( .map((type) => DropdownMenuItem<String>(
@@ -71,41 +67,20 @@ class EventBasicInfoSection extends StatelessWidget {
), ),
validator: (v) => v == null ? 'Sélectionnez un type' : null, validator: (v) => v == null ? 'Sélectionnez un type' : null,
), ),
), const SizedBox(height: 16),
const SizedBox(width: 16), _buildDateTimeRow(context),
Flexible(
fit: FlexFit.loose,
child: _buildDateTimeRow(context),
),
],
),
const SizedBox(height: 16), 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: [
Expanded(
child: GestureDetector(
onTap: () => _selectStartDateTime(context), onTap: () => _selectStartDateTime(context),
child: AbsorbPointer( child: AbsorbPointer(
child: TextFormField( child: TextFormField(
@@ -113,7 +88,6 @@ class EventBasicInfoSection extends StatelessWidget {
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Début*', labelText: 'Début*',
border: OutlineInputBorder(), border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar), suffixIcon: Icon(Icons.edit_calendar),
), ),
controller: TextEditingController( controller: TextEditingController(
@@ -124,11 +98,9 @@ class EventBasicInfoSection extends StatelessWidget {
validator: (v) => startDateTime == null ? 'Champ requis' : null, validator: (v) => startDateTime == null ? 'Champ requis' : null,
), ),
), ),
), );
),
const SizedBox(width: 16), final endField = GestureDetector(
Expanded(
child: GestureDetector(
onTap: startDateTime == null ? null : () => _selectEndDateTime(context), onTap: startDateTime == null ? null : () => _selectEndDateTime(context),
child: AbsorbPointer( child: AbsorbPointer(
child: TextFormField( child: TextFormField(
@@ -136,7 +108,6 @@ class EventBasicInfoSection extends StatelessWidget {
decoration: const InputDecoration( decoration: const InputDecoration(
labelText: 'Fin*', labelText: 'Fin*',
border: OutlineInputBorder(), border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar), suffixIcon: Icon(Icons.edit_calendar),
), ),
controller: TextEditingController( controller: TextEditingController(
@@ -154,10 +125,31 @@ class EventBasicInfoSection extends StatelessWidget {
: null, : 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,
],
);
}
},
);
} }
Future<void> _selectStartDateTime(BuildContext context) async { Future<void> _selectStartDateTime(BuildContext context) async {
@@ -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,11 +20,13 @@ 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,
spacing: 16,
runSpacing: 16,
children: [ children: [
// Bouton de suppression en mode édition // Bouton de suppression en mode édition
if (isEditMode && onDelete != null) if (isEditMode && onDelete != null)
@@ -38,17 +40,19 @@ class EventFormActions extends StatelessWidget {
onPressed: isLoading ? null : onDelete, onPressed: isLoading ? null : onDelete,
) )
else else
const SizedBox.shrink(), // Espace vide si pas en mode édition const SizedBox.shrink(),
// Boutons Annuler et Enregistrer/Créer // Boutons Annuler, Enregistrer/Créer et Valider
Row( Wrap(
mainAxisSize: MainAxisSize.min, spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: [ children: [
TextButton( TextButton(
onPressed: isLoading ? null : onCancel, onPressed: isLoading ? null : onCancel,
child: const Text('Annuler'), child: const Text('Annuler'),
), ),
const SizedBox(width: 8),
ElevatedButton.icon( ElevatedButton.icon(
icon: const Icon(Icons.check), icon: const Icon(Icons.check),
onPressed: isLoading ? null : onSubmit, onPressed: isLoading ? null : onSubmit,
@@ -60,27 +64,20 @@ class EventFormActions extends StatelessWidget {
) )
: Text(isEditMode ? 'Enregistrer' : 'Créer'), : Text(isEditMode ? 'Enregistrer' : 'Créer'),
), ),
],
),
],
),
if (!isEditMode && onSetConfirmed != null) if (!isEditMode && onSetConfirmed != null)
Center( ElevatedButton.icon(
child: Padding(
padding: const EdgeInsets.only(top: 16.0),
child: ElevatedButton.icon(
icon: const Icon(Icons.check_circle, color: Colors.white), icon: const Icon(Icons.check_circle, color: Colors.white),
label: const Text('Définir cet événement comme confirmé'), label: const Text('Créer et valider'),
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.green, backgroundColor: Colors.green,
foregroundColor: Colors.white, foregroundColor: Colors.white,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: onSetConfirmed,
),
), ),
onPressed: isLoading ? null : onSetConfirmed,
), ),
], ],
),
],
),
); );
} }
} }
@@ -36,24 +36,31 @@ 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(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Personnel', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 8),
UserMultiSelectWidget(
allUsers: allUsers, allUsers: allUsers,
selectedUserIds: selectedUserIds, selectedUserIds: selectedUserIds,
onChanged: onUserSelectionChanged, onChanged: onUserSelectionChanged,
isLoading: isLoadingUsers, isLoading: isLoadingUsers,
), ),
],
),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Expanded( Expanded(
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,7 +215,12 @@ 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);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0, top: 4.0), padding: const EdgeInsets.only(left: 8.0, top: 4.0),
child: Text( child: Text(
'TVA (${(widget.taxRate * 100).toStringAsFixed(0)}%) : ${taxAmount.toStringAsFixed(2)}', 'TVA (${(widget.taxRate * 100).toStringAsFixed(0)}%) : ${taxAmount.toStringAsFixed(2)}',
@@ -223,6 +230,57 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
fontStyle: FontStyle.italic, 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();