Browse Source

Cambios a funcionalidad Home

c90Beretta 1 month ago
parent
commit
fbcadbaaa6

+ 1 - 1
lib/mvvm/viewmodels/mesa_view_model.dart

@@ -140,7 +140,7 @@ class MesaViewModel extends ChangeNotifier {
   // }
 
   //todo: Cambio de estado de mesa provisional
-  void CambiarEstadoPedidoMesa(EstadoPedido nuevoestado) {
+  void cambiarEstadoPedidoMesa(EstadoPedido nuevoestado) {
     if (_selectedMesa != null) {
       _selectedMesa!.estado = nuevoestado;
       notifyListeners();

+ 29 - 59
lib/mvvm/views/home/home_screen.dart

@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
 import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
 import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
 import 'package:turquessa_mesas_hoster/utils/widgets/custom_card.dart';
+import 'package:turquessa_mesas_hoster/utils/widgets/get_status_style.dart';
 import 'package:turquessa_mesas_hoster/utils/widgets/navigation_rail.dart';
 
 import '../../../utils/widgets/ordenes_card.dart';
@@ -134,6 +135,8 @@ class TablaDetalles extends StatelessWidget {
 
   @override
   Widget build(BuildContext context) {
+    final mesaViewModel = Provider.of<MesaViewModel>(context, listen: true);
+    final style = getStatusStyle(status);
     return Container(
       decoration: BoxDecoration(
         color: Color.fromARGB(255, 247, 249, 250),
@@ -151,7 +154,7 @@ class TablaDetalles extends StatelessWidget {
           Container(
             padding: const EdgeInsets.all(16),
             decoration: BoxDecoration(
-              color: table.activa! ? Colors.blue : Colors.grey,
+              color: style.iconColor,
             ),
             child: Row(
               mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -205,11 +208,16 @@ class TablaDetalles extends StatelessWidget {
                     color: Colors.white.withOpacity(0.2),
                     borderRadius: BorderRadius.circular(20),
                   ),
-                  child: Text(table.activa! ? 'Activa' : 'Inactiva',
-                      style: const TextStyle(
-                        color: Colors.white,
-                        fontWeight: FontWeight.bold,
-                      )),
+                  child: GestureDetector(
+                    onTap: () {
+                      mesaViewModel.cambiarEstadoPedidoMesa(style.nextStatus);
+                    },
+                    child: Text(table.activa! ? 'Activa' : 'Inactiva',
+                        style: const TextStyle(
+                          color: Colors.white,
+                          fontWeight: FontWeight.bold,
+                        )),
+                  ),
                 ),
               ],
             ),
@@ -324,66 +332,26 @@ class TableCard extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     final status = mesa.estado ?? EstadoPedido.disponible;
+    final mesaViewModel = Provider.of<MesaViewModel>(context, listen: true);
 
-    Color backgroundColor;
-    Color iconColor;
-    IconData icon;
-    Color cardColor;
-
-    switch (status) {
-      case EstadoPedido.disponible:
-        backgroundColor = const Color.fromARGB(255, 220, 252, 232);
-        iconColor = Colors.green;
-        icon = Icons.table_restaurant_rounded;
-        cardColor = const Color.fromARGB(255, 220, 252, 232);
-        break;
-      case EstadoPedido.surtida:
-        backgroundColor = const Color.fromARGB(255, 220, 234, 254);
-        iconColor = Colors.blue;
-        icon = Icons.coffee_rounded;
-        cardColor = const Color.fromARGB(255, 220, 234, 254);
-        break;
-      case EstadoPedido.preparacion:
-        backgroundColor = const Color.fromARGB(255, 243, 232, 255);
-        iconColor = Colors.deepPurple;
-        icon = Icons.restaurant_rounded;
-        cardColor = Colors.white;
-        // cardColor = const Color.fromARGB(255, 243, 232, 255);
-        break;
-      case EstadoPedido.cobrado:
-        backgroundColor = const Color.fromARGB(255, 255, 238, 213);
-        iconColor = Colors.amber;
-        icon = Icons.attach_money_rounded;
-        cardColor = Colors.white;
-        // cardColor = const Color.fromARGB(255, 255, 238, 213);
-        break;
-      default:
-        backgroundColor = Colors.grey.shade200;
-        iconColor = Colors.grey;
-        icon = Icons.settings;
-        cardColor = Colors.white;
-        break;
-    }
+    final style = getStatusStyle(status);
 
     return Card(
       borderOnForeground: false,
-      color: cardColor,
+      color: style.cardColor,
       child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
         children: [
           IconButton(
             onPressed: () {
-              if (status == EstadoPedido.disponible) {
-                final mesaViewModel =
-                    Provider.of<MesaViewModel>(context, listen: false);
-                mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
-              }
+              mesaViewModel.cambiarEstadoPedidoMesa(style.nextStatus);
+              print('Cambiando estado de la mesa ${style.nextStatus}');
             },
             iconSize: 48,
             style: ButtonStyle(
-              backgroundColor: MaterialStateProperty.all(backgroundColor),
+              backgroundColor: MaterialStateProperty.all(style.backgroundColor),
             ),
-            icon: Icon(icon, color: iconColor),
+            icon: Icon(style.icon, color: style.iconColor),
           ),
           const SizedBox(height: 8),
           Text(
@@ -399,14 +367,16 @@ class TableCard extends StatelessWidget {
           Container(
             padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
             decoration: BoxDecoration(
-              color: backgroundColor,
+              color: style.backgroundColor,
               borderRadius: BorderRadius.circular(20),
             ),
-            child: Text(status.toString().split('.').last,
-                style: TextStyle(
-                  color: iconColor,
-                  fontWeight: FontWeight.bold,
-                )),
+            child: Text(
+              status.toString().split('.').last,
+              style: TextStyle(
+                color: style.iconColor,
+                fontWeight: FontWeight.bold,
+              ),
+            ),
           )
         ],
       ),

+ 44 - 40
lib/mvvm/views/pedido/creacion_pedido_screen.dart

@@ -88,40 +88,42 @@ class _CreacionPedidoState extends State<CreacionPedido> {
                         scrollDirection: Axis.horizontal,
                         child: SingleChildScrollView(
                           scrollDirection: Axis.vertical,
-                          child: DataTable(
-                            columnSpacing: 16,
-                            horizontalMargin: 12,
-                            dataRowHeight: 60,
-                            headingRowHeight: 48,
-                            columns: const <DataColumn>[
-                              DataColumn(label: Text('Cant')),
-                              DataColumn(label: Text('Nombre')),
-                              DataColumn(label: Text('SubTotal')),
-                              DataColumn(label: Text('Acciones')),
-                            ],
-                            rows: creacionPedidoViewModel
-                                .carrito // Aquí usamos la lista de carrito
-                                .map(
-                                  (e) => DataRow(cells: [
-                                    DataCell(
-                                      Text(e.venta.toString()),
-                                    ),
-                                    DataCell(Text(e.nombre!)),
-                                    DataCell(
-                                      Text((e.precio! * e.venta!)
-                                          .toStringAsFixed(2)),
-                                    ),
-                                    DataCell(IconButton(
-                                      color: Colors.grey[600],
-                                      icon: const Icon(Icons.edit),
-                                      onPressed: () {
-                                        creacionPedidoViewModel
-                                            .eliminarDelCarrito(e);
-                                      },
-                                    )),
-                                  ]),
-                                )
-                                .toList(),
+                          child: SizedBox(
+                            width: double.infinity,
+                            child: DataTable(
+                              columnSpacing: 16,
+                              horizontalMargin: 12,
+                              headingRowHeight: 48,
+                              columns: const <DataColumn>[
+                                DataColumn(label: Text('Cant')),
+                                DataColumn(label: Text('Nombre')),
+                                DataColumn(label: Text('SubTotal')),
+                                DataColumn(label: Text('Acciones')),
+                              ],
+                              rows: creacionPedidoViewModel
+                                  .carrito // Aquí usamos la lista de carrito
+                                  .map(
+                                    (e) => DataRow(cells: [
+                                      DataCell(
+                                        Text(e.venta.toString()),
+                                      ),
+                                      DataCell(Text(e.nombre!)),
+                                      DataCell(
+                                        Text((e.precio! * e.venta!)
+                                            .toStringAsFixed(2)),
+                                      ),
+                                      DataCell(IconButton(
+                                        color: Colors.grey[600],
+                                        icon: const Icon(Icons.edit),
+                                        onPressed: () {
+                                          creacionPedidoViewModel
+                                              .eliminarDelCarrito(e);
+                                        },
+                                      )),
+                                    ]),
+                                  )
+                                  .toList(),
+                            ),
                           ),
                         ),
                       ),
@@ -410,15 +412,14 @@ class CategoryFiltersState extends State<CategoryFilters> {
                 ),
                 const SizedBox(height: 8),
                 SizedBox(
-                  height: 50,
+                  height: 80,
                   child: ListView.builder(
                     scrollDirection: Axis.horizontal,
                     itemCount: 10,
                     itemBuilder: (context, index) {
                       return Container(
                         margin: const EdgeInsets.only(right: 8),
-                        padding: const EdgeInsets.symmetric(
-                            horizontal: 20, vertical: 10),
+                        padding: const EdgeInsets.symmetric(horizontal: 20),
                         decoration: BoxDecoration(
                           color: Colors.grey.shade200,
                           borderRadius: BorderRadius.circular(4),
@@ -427,9 +428,12 @@ class CategoryFiltersState extends State<CategoryFilters> {
                             width: 1,
                           ),
                         ),
-                        child: Text(
-                          'Item $index',
-                          style: const TextStyle(fontSize: 16),
+                        child: Center(
+                          child: Text(
+                            '${_getFilterTitle(_selectedNavIndex)} $index',
+                            style: const TextStyle(fontSize: 16),
+                            textAlign: TextAlign.center,
+                          ),
                         ),
                       );
                     },

+ 67 - 0
lib/utils/widgets/get_status_style.dart

@@ -0,0 +1,67 @@
+import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
+import 'package:turquessa_mesas_hoster/mvvm/views/home/home_screen.dart';
+import 'package:flutter/material.dart';
+
+// Clase para encapsular todas las propiedades de estilo relacionadas con el estado
+class TableStatusStyle {
+  final Color backgroundColor;
+  final Color iconColor;
+  final IconData icon;
+  final Color cardColor;
+  final EstadoPedido nextStatus;
+
+  TableStatusStyle({
+    required this.backgroundColor,
+    required this.iconColor,
+    required this.icon,
+    required this.cardColor,
+    required this.nextStatus,
+  });
+}
+
+TableStatusStyle getStatusStyle(EstadoPedido? status) {
+  status = status ?? EstadoPedido.disponible;
+
+  switch (status) {
+    case EstadoPedido.disponible:
+      return TableStatusStyle(
+        backgroundColor: const Color.fromARGB(255, 220, 252, 232),
+        iconColor: Colors.green,
+        icon: Icons.table_restaurant_rounded,
+        cardColor: const Color.fromARGB(255, 220, 252, 232),
+        nextStatus: EstadoPedido.preparacion,
+      );
+    case EstadoPedido.surtida:
+      return TableStatusStyle(
+        backgroundColor: const Color.fromARGB(255, 220, 234, 254),
+        iconColor: Colors.blue,
+        icon: Icons.coffee_rounded,
+        cardColor: const Color.fromARGB(255, 220, 234, 254),
+        nextStatus: EstadoPedido.cobrado,
+      );
+    case EstadoPedido.preparacion:
+      return TableStatusStyle(
+        backgroundColor: const Color.fromARGB(255, 243, 232, 255),
+        iconColor: Colors.deepPurple,
+        icon: Icons.restaurant_rounded,
+        cardColor: Colors.white,
+        nextStatus: EstadoPedido.surtida,
+      );
+    case EstadoPedido.cobrado:
+      return TableStatusStyle(
+        backgroundColor: const Color.fromARGB(255, 255, 238, 213),
+        iconColor: Colors.amber,
+        icon: Icons.attach_money_rounded,
+        cardColor: Colors.white,
+        nextStatus: EstadoPedido.disponible,
+      );
+    default:
+      return TableStatusStyle(
+        backgroundColor: Colors.grey.shade200,
+        iconColor: Colors.grey,
+        icon: Icons.settings,
+        cardColor: Colors.white,
+        nextStatus: EstadoPedido.disponible,
+      );
+  }
+}