|
@@ -1,8 +1,10 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
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/core/models/mesas_model.dart';
|
|
|
+import 'package:turquessa_mesas_hoster/utils/widgets/navigation_rail.dart';
|
|
|
|
|
|
+import '../../../utils/widgets/ordenes_card.dart';
|
|
|
import '../../viewmodels/viewmodels.dart';
|
|
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
@@ -13,6 +15,7 @@ class HomeScreen extends StatefulWidget {
|
|
|
}
|
|
|
|
|
|
class Formulario extends State<HomeScreen> {
|
|
|
+ int _selectedIndex = 0;
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
@@ -23,13 +26,14 @@ class Formulario extends State<HomeScreen> {
|
|
|
.sincronizarProductosYCategorias();
|
|
|
|
|
|
await mesaViewModel.sincronizarMesas();
|
|
|
- await mesaViewModel.fetchLocalAll(sinLimite: true, orderBy: 'nombre ASC');
|
|
|
+ await mesaViewModel.fetchLocal();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
final mesaViewModel = Provider.of<MesaViewModel>(context);
|
|
|
+ final loginViewModel = Provider.of<LoginViewModel>(context);
|
|
|
var _selectedIndex;
|
|
|
return Scaffold(
|
|
|
backgroundColor: Colors.grey.shade200,
|
|
@@ -38,36 +42,7 @@ class Formulario extends State<HomeScreen> {
|
|
|
),
|
|
|
body: Row(
|
|
|
children: [
|
|
|
- NavigationRail(
|
|
|
- backgroundColor: Color.fromARGB(255, 25, 30, 41),
|
|
|
- selectedIndex: _selectedIndex,
|
|
|
- onDestinationSelected: (int index) {
|
|
|
- setState(() {
|
|
|
- _selectedIndex = index;
|
|
|
- });
|
|
|
- },
|
|
|
- labelType: NavigationRailLabelType.all,
|
|
|
- destinations: const [
|
|
|
- NavigationRailDestination(
|
|
|
- icon: Icon(Icons.home, color: Colors.white),
|
|
|
- selectedIcon: Icon(Icons.home_filled),
|
|
|
- label: Text('Inicio'),
|
|
|
- ),
|
|
|
- NavigationRailDestination(
|
|
|
- icon: Icon(Icons.search),
|
|
|
- selectedIcon: Icon(
|
|
|
- Icons.search_rounded,
|
|
|
- color: Colors.white,
|
|
|
- ),
|
|
|
- label: Text('Buscar'),
|
|
|
- ),
|
|
|
- NavigationRailDestination(
|
|
|
- icon: Icon(Icons.settings),
|
|
|
- selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
|
|
|
- label: Text('Ajustes'),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
+ CustomNavigationRail(selectedIndex: _selectedIndex),
|
|
|
Expanded(
|
|
|
child: Center(
|
|
|
child: GridView.builder(
|
|
@@ -83,111 +58,240 @@ class Formulario extends State<HomeScreen> {
|
|
|
final mesa = mesaViewModel.mesas[index];
|
|
|
return GestureDetector(
|
|
|
onTap: () {
|
|
|
- mesaViewModel.selectMesa(mesa);
|
|
|
+ setState(() {
|
|
|
+ mesaViewModel.selectMesa(mesa);
|
|
|
+ });
|
|
|
},
|
|
|
child: TableCard(
|
|
|
- icon: Icons.table_chart,
|
|
|
- //TODO: Agregar campo de estatus de la mesa para definir los colores
|
|
|
- color: (mesa.activa == true) ? Colors.blue : Colors.grey,
|
|
|
- title: mesa.nombre ?? 'Mesa sin nombre',
|
|
|
+ mesa: mesa,
|
|
|
),
|
|
|
);
|
|
|
},
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
- //if (mesaViewModel.selectedMesa != null)
|
|
|
- Expanded(
|
|
|
- flex: 1,
|
|
|
- child: Container(
|
|
|
- margin: const EdgeInsets.all(10),
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: Colors.white,
|
|
|
- borderRadius: BorderRadius.circular(10),
|
|
|
- boxShadow: [
|
|
|
- BoxShadow(
|
|
|
- color: Colors.grey.withOpacity(0.2),
|
|
|
- blurRadius: 5,
|
|
|
- spreadRadius: 1,
|
|
|
- )
|
|
|
- ],
|
|
|
- ),
|
|
|
- // child: TablaDetalles(table: selectedTable!),
|
|
|
- )),
|
|
|
+ if (mesaViewModel.selectedMesa != null)
|
|
|
+ Expanded(
|
|
|
+ child: Container(
|
|
|
+ margin: const EdgeInsets.all(10),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: Colors.white,
|
|
|
+ borderRadius: BorderRadius.circular(10),
|
|
|
+ boxShadow: [
|
|
|
+ BoxShadow(
|
|
|
+ color: Colors.grey.withOpacity(0.2),
|
|
|
+ blurRadius: 5,
|
|
|
+ spreadRadius: 1,
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ child: TablaDetalles(
|
|
|
+ status: EstadoPedido.disponible,
|
|
|
+ table: mesaViewModel.selectedMesa ??
|
|
|
+ Mesa(
|
|
|
+ activa: false,
|
|
|
+ id: 0,
|
|
|
+ nombre: 'Mesa sin nombre',
|
|
|
+ estado: EstadoPedido.disponible)),
|
|
|
+ )),
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class TableCard extends StatelessWidget {
|
|
|
- final IconData icon;
|
|
|
- final Color color;
|
|
|
- final String title;
|
|
|
- const TableCard(
|
|
|
- {super.key,
|
|
|
- required this.icon,
|
|
|
- required this.color,
|
|
|
- required this.title});
|
|
|
+class TablaDetalles extends StatelessWidget {
|
|
|
+ final Mesa table;
|
|
|
+ final EstadoPedido status;
|
|
|
+
|
|
|
+ const TablaDetalles({
|
|
|
+ Key? key,
|
|
|
+ required this.table,
|
|
|
+ required this.status,
|
|
|
+ }) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- return Card(
|
|
|
- color: color,
|
|
|
+ return Container(
|
|
|
+ margin: const EdgeInsets.all(10),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: Colors.white,
|
|
|
+ borderRadius: BorderRadius.circular(10),
|
|
|
+ boxShadow: [
|
|
|
+ BoxShadow(
|
|
|
+ color: Colors.grey.withOpacity(0.2),
|
|
|
+ blurRadius: 5,
|
|
|
+ spreadRadius: 1,
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
child: Column(
|
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
|
children: [
|
|
|
- Icon(
|
|
|
- icon,
|
|
|
- size: 50,
|
|
|
- color: Colors.white,
|
|
|
+ // Header
|
|
|
+ Container(
|
|
|
+ padding: const EdgeInsets.all(16),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: table.activa! ? Colors.blue : Colors.grey,
|
|
|
+ borderRadius:
|
|
|
+ const BorderRadius.vertical(top: Radius.circular(10)),
|
|
|
+ ),
|
|
|
+ child: Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
+ children: [
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ const Icon(Icons.table_restaurant,
|
|
|
+ color: Colors.white, size: 24),
|
|
|
+ const SizedBox(width: 8),
|
|
|
+ Text(
|
|
|
+ table.nombre ?? 'Mesa sin nombre',
|
|
|
+ style: const TextStyle(
|
|
|
+ color: Colors.white,
|
|
|
+ fontSize: 20,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ padding:
|
|
|
+ const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ 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,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ // Contenido scrolleable
|
|
|
+ Expanded(
|
|
|
+ child: SingleChildScrollView(
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.all(16),
|
|
|
+ child: Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ Text(
|
|
|
+ 'ID: ${table.id}',
|
|
|
+ style: const TextStyle(fontSize: 16),
|
|
|
+ ),
|
|
|
+ const SizedBox(height: 16),
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ const Text('Estado: '),
|
|
|
+ Text(
|
|
|
+ status.toString().split('.').last,
|
|
|
+ style: const TextStyle(
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ color: Colors.blue,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ const SizedBox(height: 16),
|
|
|
+ // IconDataByStatus(status: status),
|
|
|
+ const SizedBox(height: 16),
|
|
|
+ OrdenesScreen(),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
),
|
|
|
- Text(
|
|
|
- title,
|
|
|
- style: const TextStyle(color: Colors.white, fontSize: 20),
|
|
|
- )
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class TableDetailsPanel extends StatelessWidget {
|
|
|
- final TableItem table;
|
|
|
-
|
|
|
- const TableDetailsPanel({
|
|
|
- Key? key,
|
|
|
- required this.table,
|
|
|
- }) : super(key: key);
|
|
|
+class TableCard extends StatelessWidget {
|
|
|
+ final Mesa mesa;
|
|
|
+ const TableCard({
|
|
|
+ super.key,
|
|
|
+ required this.mesa,
|
|
|
+ });
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- return Column(
|
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
- children: [
|
|
|
- // Encabezado del panel
|
|
|
- Container(
|
|
|
- padding: const EdgeInsets.all(16),
|
|
|
- decoration: BoxDecoration(
|
|
|
- borderRadius: const BorderRadius.vertical(top: Radius.circular(10)),
|
|
|
- ),
|
|
|
- child: Row(
|
|
|
- children: [
|
|
|
- Icon(Icons.person, color: Colors.white, size: 24),
|
|
|
- const SizedBox(width: 8),
|
|
|
- Text(
|
|
|
- table.name,
|
|
|
- style: const TextStyle(
|
|
|
- color: Colors.white,
|
|
|
- fontSize: 20,
|
|
|
- fontWeight: FontWeight.bold,
|
|
|
- ),
|
|
|
- ),
|
|
|
- ],
|
|
|
+ final status = mesa.estado ?? EstadoPedido.disponible;
|
|
|
+
|
|
|
+ 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.kitchen_rounded;
|
|
|
+ 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 = const Color.fromARGB(255, 255, 238, 213);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ backgroundColor = Colors.grey.shade200;
|
|
|
+ iconColor = Colors.grey;
|
|
|
+ icon = Icons.settings;
|
|
|
+ cardColor = Colors.white;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return Card(
|
|
|
+ color: 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);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ iconSize: 48,
|
|
|
+ style: ButtonStyle(
|
|
|
+ backgroundColor: MaterialStateProperty.all(backgroundColor),
|
|
|
+ ),
|
|
|
+ icon: Icon(icon, color: iconColor),
|
|
|
),
|
|
|
- ),
|
|
|
- // Contenido específico según el tipo
|
|
|
- ],
|
|
|
+ const SizedBox(height: 8),
|
|
|
+ Text(
|
|
|
+ mesa.nombre ?? 'Mesa sin nombre',
|
|
|
+ style: TextStyle(
|
|
|
+ color: status == EstadoPedido.disponible
|
|
|
+ ? Colors.black
|
|
|
+ : Colors.black87,
|
|
|
+ fontSize: 20,
|
|
|
+ fontWeight: FontWeight.w500,
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
}
|