home_screen.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
  4. import 'package:turquessa_mesas_hoster/core/models/mesas_model.dart';
  5. import '../../viewmodels/viewmodels.dart';
  6. class HomeScreen extends StatefulWidget {
  7. const HomeScreen({super.key});
  8. @override
  9. Formulario createState() => Formulario();
  10. }
  11. class Formulario extends State<HomeScreen> {
  12. @override
  13. void initState() {
  14. super.initState();
  15. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  16. WidgetsBinding.instance.addPostFrameCallback((_) async {
  17. Provider.of<ProductoViewModel>(context, listen: false)
  18. .sincronizarProductosYCategorias();
  19. await mesaViewModel.sincronizarMesas();
  20. await mesaViewModel.fetchLocalAll(sinLimite: true, orderBy: 'nombre ASC');
  21. });
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. final mesaViewModel = Provider.of<MesaViewModel>(context);
  26. final loginViewModel = Provider.of<LoginViewModel>(context);
  27. var _selectedIndex;
  28. return Scaffold(
  29. backgroundColor: Colors.grey.shade200,
  30. appBar: AppBar(
  31. title: const CustomAppbar(),
  32. ),
  33. body: Row(
  34. children: [
  35. NavigationRail(
  36. backgroundColor: Color.fromARGB(255, 25, 30, 41),
  37. selectedIndex: _selectedIndex,
  38. onDestinationSelected: (int index) {
  39. setState(() {
  40. _selectedIndex = index;
  41. });
  42. if (index == 3) {
  43. loginViewModel.showExitConfirmationDialog(context);
  44. }
  45. },
  46. labelType: NavigationRailLabelType.all,
  47. destinations: const [
  48. NavigationRailDestination(
  49. icon: Icon(Icons.home, color: Colors.white),
  50. selectedIcon: Icon(Icons.home_filled),
  51. label: Text('Inicio'),
  52. ),
  53. NavigationRailDestination(
  54. icon: Icon(Icons.search),
  55. selectedIcon: Icon(
  56. Icons.search_rounded,
  57. color: Colors.white,
  58. ),
  59. label: Text('Buscar'),
  60. ),
  61. NavigationRailDestination(
  62. icon: Icon(Icons.settings),
  63. selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
  64. label: Text('Ajustes'),
  65. ),
  66. NavigationRailDestination(
  67. icon: Icon(Icons.logout),
  68. selectedIcon: Icon(Icons.logout, color: Colors.white),
  69. label: Text('Cerrar Sesión'),
  70. ),
  71. ],
  72. ),
  73. Expanded(
  74. child: Center(
  75. child: GridView.builder(
  76. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  77. crossAxisCount: 4,
  78. childAspectRatio: 1.0,
  79. crossAxisSpacing: 10.0,
  80. mainAxisSpacing: 10.0,
  81. ),
  82. padding: const EdgeInsets.all(10),
  83. itemCount: mesaViewModel.mesas.length,
  84. itemBuilder: (context, index) {
  85. final mesa = mesaViewModel.mesas[index];
  86. return GestureDetector(
  87. onTap: () {
  88. mesaViewModel.selectMesa(mesa);
  89. },
  90. child: TableCard(
  91. icon: Icons.table_chart,
  92. //TODO: Agregar campo de estatus de la mesa para definir los colores
  93. color: (mesa.activa == true) ? Colors.blue : Colors.grey,
  94. title: mesa.nombre ?? 'Mesa sin nombre',
  95. ),
  96. );
  97. },
  98. ),
  99. ),
  100. ),
  101. //if (mesaViewModel.selectedMesa != null)
  102. Expanded(
  103. flex: 1,
  104. child: Container(
  105. margin: const EdgeInsets.all(10),
  106. decoration: BoxDecoration(
  107. color: Colors.white,
  108. borderRadius: BorderRadius.circular(10),
  109. boxShadow: [
  110. BoxShadow(
  111. color: Colors.grey.withOpacity(0.2),
  112. blurRadius: 5,
  113. spreadRadius: 1,
  114. )
  115. ],
  116. ),
  117. // child: TablaDetalles(table: selectedTable!),
  118. )),
  119. ],
  120. ),
  121. );
  122. }
  123. }
  124. class TableCard extends StatelessWidget {
  125. final IconData icon;
  126. final Color color;
  127. final String title;
  128. const TableCard(
  129. {super.key,
  130. required this.icon,
  131. required this.color,
  132. required this.title});
  133. @override
  134. Widget build(BuildContext context) {
  135. return Card(
  136. color: color,
  137. child: Column(
  138. mainAxisAlignment: MainAxisAlignment.center,
  139. children: [
  140. Icon(
  141. icon,
  142. size: 50,
  143. color: Colors.white,
  144. ),
  145. Text(
  146. title,
  147. style: const TextStyle(color: Colors.white, fontSize: 20),
  148. )
  149. ],
  150. ),
  151. );
  152. }
  153. }
  154. class TableDetailsPanel extends StatelessWidget {
  155. final TableItem table;
  156. const TableDetailsPanel({
  157. Key? key,
  158. required this.table,
  159. }) : super(key: key);
  160. @override
  161. Widget build(BuildContext context) {
  162. return Column(
  163. crossAxisAlignment: CrossAxisAlignment.start,
  164. children: [
  165. // Encabezado del panel
  166. Container(
  167. padding: const EdgeInsets.all(16),
  168. decoration: BoxDecoration(
  169. borderRadius: const BorderRadius.vertical(top: Radius.circular(10)),
  170. ),
  171. child: Row(
  172. children: [
  173. Icon(Icons.person, color: Colors.white, size: 24),
  174. const SizedBox(width: 8),
  175. Text(
  176. table.name,
  177. style: const TextStyle(
  178. color: Colors.white,
  179. fontSize: 20,
  180. fontWeight: FontWeight.bold,
  181. ),
  182. ),
  183. ],
  184. ),
  185. ),
  186. // Contenido específico según el tipo
  187. ],
  188. );
  189. }
  190. }