feat: Ajout de la gestion de la quantité pour les options d'événement
This commit is contained in:
@@ -62,7 +62,9 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
children: [
|
||||
...enrichedOptions.map((opt) {
|
||||
final price = (opt['price'] ?? 0.0) as num;
|
||||
final isNegative = price < 0;
|
||||
final quantity = (opt['quantity'] ?? 1) as int;
|
||||
final totalPrice = price * quantity;
|
||||
final isNegative = totalPrice < 0;
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(Icons.tune, color: AppColors.rouge),
|
||||
@@ -72,8 +74,11 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
: opt['name'] ?? '',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: opt['details'] != null && opt['details'].toString().trim().isNotEmpty
|
||||
? Text(
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (opt['details'] != null && opt['details'].toString().trim().isNotEmpty)
|
||||
Text(
|
||||
opt['details'].toString().trim(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.normal,
|
||||
@@ -82,7 +87,8 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
else
|
||||
Text(
|
||||
'Aucun détail disponible',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.normal,
|
||||
@@ -91,10 +97,24 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
if (quantity > 1 && canViewPrices)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4.0),
|
||||
child: Text(
|
||||
'${currencyFormat.format(price)} × $quantity',
|
||||
style: TextStyle(
|
||||
color: Colors.grey[700],
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: canViewPrices
|
||||
? Text(
|
||||
(isNegative ? '- ' : '+ ') +
|
||||
currencyFormat.format(price.abs()),
|
||||
currencyFormat.format(totalPrice.abs()),
|
||||
style: TextStyle(
|
||||
color: isNegative ? Colors.red : AppColors.noir,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -118,7 +138,11 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildTotalPrice(BuildContext context, List<Map<String, dynamic>> options, NumberFormat currencyFormat) {
|
||||
final optionsTotal = options.fold<num>(0, (sum, opt) => sum + (opt['price'] ?? 0.0));
|
||||
final optionsTotal = options.fold<num>(0, (sum, opt) {
|
||||
final price = opt['price'] ?? 0.0;
|
||||
final quantity = opt['quantity'] ?? 1;
|
||||
return sum + (price * quantity);
|
||||
});
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
||||
@@ -166,6 +190,8 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
'name': firestoreData['name'], // Récupéré depuis Firestore
|
||||
'details': firestoreData['details'] ?? '', // Récupéré depuis Firestore
|
||||
'price': optionData['price'], // Prix choisi par l'utilisateur
|
||||
'quantity': optionData['quantity'] ?? 1, // Quantité
|
||||
'isQuantitative': firestoreData['isQuantitative'] ?? false,
|
||||
'valMin': firestoreData['valMin'],
|
||||
'valMax': firestoreData['valMax'],
|
||||
});
|
||||
@@ -176,6 +202,8 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
'name': 'Option supprimée (ID: ${optionData['id']})',
|
||||
'details': 'Cette option n\'existe plus dans la base de données',
|
||||
'price': optionData['price'],
|
||||
'quantity': optionData['quantity'] ?? 1,
|
||||
'isQuantitative': false,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -185,6 +213,8 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
'name': optionData['name'] ?? 'Option inconnue',
|
||||
'details': optionData['details'] ?? 'Aucun détail disponible',
|
||||
'price': optionData['price'] ?? 0.0,
|
||||
'quantity': optionData['quantity'] ?? 1,
|
||||
'isQuantitative': false,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -195,6 +225,8 @@ class EventOptionsDisplayWidget extends StatelessWidget {
|
||||
'name': 'Erreur de chargement (ID: ${optionData['id']})',
|
||||
'details': 'Impossible de charger les détails de cette option',
|
||||
'price': optionData['price'] ?? 0.0,
|
||||
'quantity': optionData['quantity'] ?? 1,
|
||||
'isQuantitative': false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user