123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- 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 '../../../utils/widgets/ordenes_card.dart';
- import '../../viewmodels/viewmodels.dart';
- class HomeScreen extends StatefulWidget {
- const HomeScreen({super.key});
- @override
- Formulario createState() => Formulario();
- }
- class Formulario extends State<HomeScreen> {
- int _selectedIndex = 0;
- @override
- void initState() {
- super.initState();
- final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
- WidgetsBinding.instance.addPostFrameCallback((_) async {
- Provider.of<ProductoViewModel>(context, listen: false)
- .sincronizarProductosYCategorias();
- await mesaViewModel.sincronizarMesas();
- await mesaViewModel.fetchLocalAll(sinLimite: true, orderBy: 'nombre ASC');
- });
- }
- @override
- Widget build(BuildContext context) {
- final mesaViewModel = Provider.of<MesaViewModel>(context);
- return Scaffold(
- backgroundColor: Colors.grey.shade200,
- appBar: AppBar(
- title: const CustomAppbar(),
- ),
- 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'),
- ),
- ],
- ),
- Expanded(
- child: Center(
- child: GridView.builder(
- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 4,
- childAspectRatio: 1.0,
- crossAxisSpacing: 10.0,
- mainAxisSpacing: 10.0,
- ),
- padding: const EdgeInsets.all(10),
- itemCount: mesaViewModel.mesas.length,
- itemBuilder: (context, index) {
- final mesa = mesaViewModel.mesas[index];
- return GestureDetector(
- onTap: () {
- 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',
- ),
- );
- },
- ),
- ),
- ),
- 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});
- @override
- Widget build(BuildContext context) {
- return Card(
- color: color,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Icon(
- icon,
- size: 50,
- color: Colors.white,
- ),
- Text(
- title,
- style: const TextStyle(color: Colors.white, fontSize: 20),
- )
- ],
- ),
- );
- }
- }
- 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 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(
- children: [
- // 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),
- const OrdenesScreen(),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
- class IconDataByStatus extends StatelessWidget {
- final EstadoPedido status;
- const IconDataByStatus({Key? key, required this.status});
- @override
- Widget build(BuildContext context) {
- switch (status) {
- case EstadoPedido.disponible:
- return IconButton(
- onPressed: () {
- final mesaViewModel =
- Provider.of<MesaViewModel>(context, listen: false);
- mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
- },
- style: ButtonStyle(
- backgroundColor: MaterialStateProperty.all(
- const Color.fromARGB(255, 220, 252, 232)),
- ),
- icon: const Icon(Icons.table_restaurant_rounded, color: Colors.green),
- );
- case EstadoPedido.surtida:
- return IconButton(
- onPressed: () {},
- icon: const Icon(Icons.coffee_rounded,
- color: Color.fromARGB(255, 220, 234, 254)),
- );
- case EstadoPedido.preparacion:
- return IconButton(
- onPressed: () {},
- icon: const Icon(Icons.kitchen_rounded,
- color: Color.fromARGB(255, 243, 232, 255)),
- );
- case EstadoPedido.cobrado:
- return IconButton(
- onPressed: () {},
- icon: const Icon(Icons.money_rounded,
- color: Color.fromARGB(255, 255, 238, 213)),
- );
- default:
- return IconButton(
- onPressed: () {},
- icon: const Icon(Icons.check_circle, color: Colors.grey),
- );
- }
- }
- }
|