|
@@ -129,6 +129,46 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
|
// print('Total con descuento aplicado: $totalPedido');
|
|
|
}
|
|
|
|
|
|
+ bool validarMinimosSeleccionados() {
|
|
|
+ for (var item in carrito) {
|
|
|
+ for (var categoriaId in item.selectableToppings.keys) {
|
|
|
+ final categoria = categorias.firstWhere((c) => c.id == categoriaId);
|
|
|
+ final minimoRequerido = categoria.minimo ?? 0;
|
|
|
+ final seleccionados = item.selectedToppings[categoriaId]?.length ?? 0;
|
|
|
+
|
|
|
+ if (minimoRequerido > 0 && seleccionados < minimoRequerido) {
|
|
|
+ showDialog(
|
|
|
+ context: context,
|
|
|
+ builder: (BuildContext context) {
|
|
|
+ return AlertDialog(
|
|
|
+ title: const Text('Faltan Toppings',
|
|
|
+ style:
|
|
|
+ TextStyle(fontWeight: FontWeight.w500, fontSize: 22)),
|
|
|
+ content: Text(
|
|
|
+ 'El producto ${item.producto.nombre} requiere que seleccione al menos $minimoRequerido topping en la categoría ${categoria.nombre}.',
|
|
|
+ style: TextStyle(fontSize: 18)),
|
|
|
+ actions: <Widget>[
|
|
|
+ TextButton(
|
|
|
+ onPressed: () => Navigator.of(context).pop(),
|
|
|
+ child: const Text('Aceptar'),
|
|
|
+ style: ButtonStyle(
|
|
|
+ padding: MaterialStatePropertyAll(
|
|
|
+ EdgeInsets.fromLTRB(20, 10, 20, 10)),
|
|
|
+ backgroundColor:
|
|
|
+ MaterialStatePropertyAll(AppTheme.tertiary),
|
|
|
+ foregroundColor:
|
|
|
+ MaterialStatePropertyAll(AppTheme.quaternary))),
|
|
|
+ ],
|
|
|
+ );
|
|
|
+ },
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
void _finalizeOrder() async {
|
|
|
if (carrito.isEmpty) {
|
|
|
showDialog(
|
|
@@ -159,6 +199,9 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
|
);
|
|
|
return;
|
|
|
}
|
|
|
+ if (!validarMinimosSeleccionados()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
await _promptForCustomerName();
|
|
|
}
|
|
@@ -1122,9 +1165,13 @@ class _PedidoFormState extends State<PedidoForm> {
|
|
|
return ExpansionTile(
|
|
|
initiallyExpanded: true,
|
|
|
title: Text(
|
|
|
- '${categoria.nombre} (Hasta ${categoria.maximo ?? 0})',
|
|
|
+ '${categoria.nombre}'
|
|
|
+ ' (Hasta ${categoria.maximo ?? 0})'
|
|
|
+ ' ${(categoria.minimo ?? 0) > 0 ? " (Mínimo ${categoria.minimo})" : ""}',
|
|
|
style: const TextStyle(
|
|
|
- fontWeight: FontWeight.bold, fontSize: 16),
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ fontSize: 16,
|
|
|
+ ),
|
|
|
),
|
|
|
children: availableToppings.map((topping) {
|
|
|
bool isSelected = item
|