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 {
_isLoading = true;
_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
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)),
body: SingleChildScrollView(
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1200),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 32, vertical: 32),
padding: EdgeInsets.symmetric(
horizontal: isMobile ? 16 : 32,
vertical: 32),
child: _buildFormContent(isMobile),
),
)),
),
),
),
),
@@ -196,6 +238,10 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildCard(
title: 'Informations générales',
icon: Icons.event_note,
children: [
EventBasicInfoSection(
nameController: controller.nameController,
@@ -205,17 +251,16 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
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:
() {}, // Géré automatiquement par le contrôleur
onAnyFieldChanged: () {},
),
const SizedBox(height: 16),
OptionSelectorWidget(
eventType: controller
.selectedEventTypeId, // Utilise l'ID au lieu du nom
eventType: controller.selectedEventTypeId,
selectedOptions: controller.selectedOptions,
onChanged: controller.setSelectedOptions,
onRemove: (optionId) {
@@ -227,8 +272,10 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
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,7 +285,11 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
eventId: widget.event?.id,
eventTypeId: controller.selectedEventTypeId,
),
const SizedBox(height: 16),
const SizedBox(height: 24),
_buildCard(
title: 'Détails & Logistique',
icon: Icons.location_on_outlined,
children: [
EventDetailsSection(
descriptionController: controller.descriptionController,
installationController: controller.installationController,
@@ -248,9 +299,15 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
contactEmailController: controller.contactEmailController,
contactPhoneController: controller.contactPhoneController,
isMobile: isMobile,
onAnyFieldChanged:
() {}, // Géré automatiquement par le contrôleur
onAnyFieldChanged: () {},
),
],
),
const SizedBox(height: 24),
_buildCard(
title: 'Personnel & Documents',
icon: Icons.group_outlined,
children: [
EventStaffAndDocumentsSection(
allUsers: controller.allUsers,
selectedUserIds: controller.selectedUserIds,
@@ -264,24 +321,57 @@ class _EventAddEditPageState extends State<EventAddEditPage> {
isMobile: isMobile,
onPickAndUploadFiles: controller.pickAndUploadFiles,
),
],
),
if (controller.error != null)
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(
controller.error!,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red.shade700),
),
),
],
),
),
),
if (controller.success != null)
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(
controller.success!,
style: const TextStyle(color: Colors.green),
textAlign: TextAlign.center,
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
],
),
);
@@ -262,11 +262,18 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
);
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(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return const Center(child: CircularProgressIndicator());
useRootNavigator: true,
builder: (BuildContext dialogContext) {
return const PopScope(
canPop: false,
child: Center(child: CircularProgressIndicator()),
);
},
);
@@ -277,15 +284,21 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
'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) {
final eventProvider = Provider.of<EventProvider>(context, listen: false);
final userProvider = Provider.of<LocalUserProvider>(context, listen: false);
if (userProvider.currentUser != null) {
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(
const SnackBar(
content: Text('Retour en arrière effectué avec succès'),
@@ -294,8 +307,9 @@ class _EventPreparationButtonsState extends State<EventPreparationButtons> {
);
}
} catch (e) {
navigator.pop(); // Fermer le loader
if (context.mounted) {
Navigator.of(context).pop(); // Fermer le loader
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Erreur : $e'),
@@ -43,6 +43,7 @@ class _EventAssignedEquipmentSectionState
final Map<String, EquipmentModel> _equipmentCache = {};
final Map<String, ContainerModel> _containerCache = {};
bool _isLoading = true;
final ScrollController _scrollController = ScrollController();
@override
void initState() {
@@ -50,6 +51,12 @@ class _EventAssignedEquipmentSectionState
_loadEquipmentAndContainers();
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override
void didUpdateWidget(EventAssignedEquipmentSection oldWidget) {
super.didUpdateWidget(oldWidget);
@@ -394,40 +401,52 @@ class _EventAssignedEquipmentSectionState
widget.assignedEquipment.length + widget.assignedContainers.length;
return Card(
elevation: 2,
elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: Colors.grey.shade200, width: 1),
),
child: Padding(
padding: const EdgeInsets.all(20),
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// En-tête
SizedBox(
width: double.infinity,
child: Wrap(
spacing: 16,
runSpacing: 16,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.spaceBetween,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(8),
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.rouge.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
color: AppColors.rouge.withOpacity(0.1),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.inventory_2,
color: AppColors.rouge,
size: 24,
size: 22,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Matériel assigné',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
Text(
@@ -439,13 +458,17 @@ class _EventAssignedEquipmentSectionState
),
],
),
],
),
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'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
onPressed: _canAddMaterial ? _openSelectionDialog : null,
icon: Icon(Icons.add,
@@ -463,6 +486,9 @@ class _EventAssignedEquipmentSectionState
),
],
),
],
),
),
// Message si dates non sélectionnées
if (!_canAddMaterial)
@@ -522,11 +548,25 @@ class _EventAssignedEquipmentSectionState
),
)
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,
children: [
// Conteneurs
if (widget.assignedContainers.isNotEmpty) ...[
if (hasContainers) ...[
Text(
'Boîtes (${widget.assignedContainers.length})',
style: const TextStyle(
@@ -540,10 +580,14 @@ class _EventAssignedEquipmentSectionState
return _buildContainerItem(container);
}),
const SizedBox(height: 16),
]
],
);
// Équipements directs (qui ne sont PAS dans un conteneur assigné)
if (_getStandaloneEquipment().isNotEmpty) ...[
final equipmentContent = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasEquipment) ...[
Text(
'Équipements (${_getStandaloneEquipment().length})',
style: const TextStyle(
@@ -556,8 +600,31 @@ class _EventAssignedEquipmentSectionState
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 DateTime? startDateTime;
final DateTime? endDateTime;
final List<Map<String, dynamic>> selectedOptions;
final Function(String?) onEventTypeChanged;
final Function(DateTime?) onStartDateTimeChanged;
final Function(DateTime?) onEndDateTimeChanged;
@@ -25,6 +26,7 @@ class EventBasicInfoSection extends StatelessWidget {
required this.selectedEventTypeId,
required this.startDateTime,
required this.endDateTime,
required this.selectedOptions,
required this.onEventTypeChanged,
required this.onStartDateTimeChanged,
required this.onEndDateTimeChanged,
@@ -36,7 +38,6 @@ class EventBasicInfoSection extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildSectionTitle('Informations principales'),
TextFormField(
controller: nameController,
decoration: const InputDecoration(
@@ -50,12 +51,7 @@ class EventBasicInfoSection extends StatelessWidget {
if (isLoadingEventTypes)
const Center(child: CircularProgressIndicator())
else
Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
fit: FlexFit.loose,
child: DropdownButtonFormField<String>(
DropdownButtonFormField<String>(
initialValue: selectedEventTypeId,
items: eventTypes
.map((type) => DropdownMenuItem<String>(
@@ -71,41 +67,20 @@ class EventBasicInfoSection extends StatelessWidget {
),
validator: (v) => v == null ? 'Sélectionnez un type' : null,
),
),
const SizedBox(width: 16),
Flexible(
fit: FlexFit.loose,
child: _buildDateTimeRow(context),
),
],
),
const SizedBox(height: 16),
_buildDateTimeRow(context),
const SizedBox(height: 16),
PriceHtTtcFields(
basePriceController: basePriceController,
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) {
return Row(
children: [
Expanded(
child: GestureDetector(
final startField = GestureDetector(
onTap: () => _selectStartDateTime(context),
child: AbsorbPointer(
child: TextFormField(
@@ -113,7 +88,6 @@ class EventBasicInfoSection extends StatelessWidget {
decoration: const InputDecoration(
labelText: 'Début*',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar),
),
controller: TextEditingController(
@@ -124,11 +98,9 @@ class EventBasicInfoSection extends StatelessWidget {
validator: (v) => startDateTime == null ? 'Champ requis' : null,
),
),
),
),
const SizedBox(width: 16),
Expanded(
child: GestureDetector(
);
final endField = GestureDetector(
onTap: startDateTime == null ? null : () => _selectEndDateTime(context),
child: AbsorbPointer(
child: TextFormField(
@@ -136,7 +108,6 @@ class EventBasicInfoSection extends StatelessWidget {
decoration: const InputDecoration(
labelText: 'Fin*',
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.calendar_today),
suffixIcon: Icon(Icons.edit_calendar),
),
controller: TextEditingController(
@@ -154,10 +125,31 @@ class EventBasicInfoSection extends StatelessWidget {
: 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 {
@@ -56,8 +56,6 @@ class _EventDetailsSectionState extends State<EventDetailsSection> {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildSectionTitle('Détails'),
// Description et champs de contact
widget.isMobile
? _buildMobileLayout()
@@ -88,7 +86,8 @@ class _EventDetailsSectionState extends State<EventDetailsSection> {
],
),
_buildSectionTitle('Adresse*'),
const SizedBox(height: 20),
TextFormField(
controller: widget.addressController,
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
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(height: 24),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
return Padding(
padding: const EdgeInsets.only(top: 24.0),
child: Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 16,
runSpacing: 16,
children: [
// Bouton de suppression en mode édition
if (isEditMode && onDelete != null)
@@ -38,17 +40,19 @@ class EventFormActions extends StatelessWidget {
onPressed: isLoading ? null : onDelete,
)
else
const SizedBox.shrink(), // Espace vide si pas en mode édition
const SizedBox.shrink(),
// Boutons Annuler et Enregistrer/Créer
Row(
mainAxisSize: MainAxisSize.min,
// 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'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
icon: const Icon(Icons.check),
onPressed: isLoading ? null : onSubmit,
@@ -60,27 +64,20 @@ class EventFormActions extends StatelessWidget {
)
: Text(isEditMode ? 'Enregistrer' : 'Créer'),
),
],
),
],
),
if (!isEditMode && onSetConfirmed != null)
Center(
child: Padding(
padding: const EdgeInsets.only(top: 16.0),
child: ElevatedButton.icon(
ElevatedButton.icon(
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(
backgroundColor: Colors.green,
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(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildSectionTitle('Personnel'),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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,
selectedUserIds: selectedUserIds,
onChanged: onUserSelectionChanged,
isLoading: isLoadingUsers,
),
],
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionTitle('Documents'),
const Text('Documents', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 8),
if (isMobile)
_buildMobileDocumentUpload()
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() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -8,12 +8,14 @@ class PriceHtTtcFields extends StatefulWidget {
final TextEditingController basePriceController;
final VoidCallback onPriceChanged;
final double taxRate;
final List<Map<String, dynamic>> selectedOptions;
const PriceHtTtcFields({
super.key,
required this.basePriceController,
required this.onPriceChanged,
this.taxRate = 0.20,
this.selectedOptions = const [],
});
@override
@@ -133,7 +135,7 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Prix',
'Prix Base',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
),
const SizedBox(height: 8),
@@ -205,7 +207,7 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
],
),
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: (context) {
final htText = _htController.text.replaceAll(',', '.');
@@ -213,7 +215,12 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
if (htValue != null) {
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),
child: Text(
'TVA (${(widget.taxRate * 100).toStringAsFixed(0)}%) : ${taxAmount.toStringAsFixed(2)}',
@@ -223,6 +230,57 @@ class _PriceHtTtcFieldsState extends State<PriceHtTtcFields> {
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();