home_screen.dart 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
  4. import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
  5. import 'package:turquessa_mesas_hoster/core/models/mesas_model.dart';
  6. import '../../viewmodels/viewmodels.dart';
  7. class HomeScreen extends StatefulWidget {
  8. const HomeScreen({super.key});
  9. @override
  10. Formulario createState() => Formulario();
  11. }
  12. class Formulario extends State<HomeScreen> {
  13. int _selectedIndex = 0;
  14. @override
  15. void initState() {
  16. super.initState();
  17. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  18. WidgetsBinding.instance.addPostFrameCallback((_) async {
  19. Provider.of<ProductoViewModel>(context, listen: false)
  20. .sincronizarProductosYCategorias();
  21. await mesaViewModel.sincronizarMesas();
  22. await mesaViewModel.fetchLocalAll(sinLimite: true, orderBy: 'nombre ASC');
  23. });
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. final mesaViewModel = Provider.of<MesaViewModel>(context);
  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. },
  43. labelType: NavigationRailLabelType.all,
  44. destinations: const [
  45. NavigationRailDestination(
  46. icon: Icon(Icons.home, color: Colors.white),
  47. selectedIcon: Icon(Icons.home_filled),
  48. label: Text('Inicio'),
  49. ),
  50. NavigationRailDestination(
  51. icon: Icon(Icons.search),
  52. selectedIcon: Icon(
  53. Icons.search_rounded,
  54. color: Colors.white,
  55. ),
  56. label: Text('Buscar'),
  57. ),
  58. NavigationRailDestination(
  59. icon: Icon(Icons.settings),
  60. selectedIcon: Icon(Icons.settings_rounded, color: Colors.white),
  61. label: Text('Ajustes'),
  62. ),
  63. ],
  64. ),
  65. Expanded(
  66. child: Center(
  67. child: GridView.builder(
  68. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  69. crossAxisCount: 4,
  70. childAspectRatio: 1.0,
  71. crossAxisSpacing: 10.0,
  72. mainAxisSpacing: 10.0,
  73. ),
  74. padding: const EdgeInsets.all(10),
  75. itemCount: mesaViewModel.mesas.length,
  76. itemBuilder: (context, index) {
  77. final mesa = mesaViewModel.mesas[index];
  78. return GestureDetector(
  79. onTap: () {
  80. setState(() {
  81. mesaViewModel.selectMesa(mesa);
  82. });
  83. },
  84. child: TableCard(
  85. icon: Icons.table_chart,
  86. //TODO: Agregar campo de estatus de la mesa para definir los colores
  87. color: (mesa.activa == true) ? Colors.blue : Colors.grey,
  88. title: mesa.nombre ?? 'Mesa sin nombre',
  89. ),
  90. );
  91. },
  92. ),
  93. ),
  94. ),
  95. if (mesaViewModel.selectedMesa != null)
  96. Expanded(
  97. flex: 1,
  98. child: Container(
  99. margin: const EdgeInsets.all(10),
  100. decoration: BoxDecoration(
  101. color: Colors.white,
  102. borderRadius: BorderRadius.circular(10),
  103. boxShadow: [
  104. BoxShadow(
  105. color: Colors.grey.withOpacity(0.2),
  106. blurRadius: 5,
  107. spreadRadius: 1,
  108. )
  109. ],
  110. ),
  111. child: TablaDetalles(
  112. table: mesaViewModel.selectedMesa ??
  113. Mesa(
  114. activa: false, id: 0, nombre: 'Mesa sin nombre')),
  115. )),
  116. ],
  117. ),
  118. );
  119. }
  120. }
  121. class TableCard extends StatelessWidget {
  122. final IconData icon;
  123. final Color color;
  124. final String title;
  125. const TableCard(
  126. {super.key,
  127. required this.icon,
  128. required this.color,
  129. required this.title});
  130. @override
  131. Widget build(BuildContext context) {
  132. return Card(
  133. color: color,
  134. child: Column(
  135. mainAxisAlignment: MainAxisAlignment.center,
  136. children: [
  137. Icon(
  138. icon,
  139. size: 50,
  140. color: Colors.white,
  141. ),
  142. Text(
  143. title,
  144. style: const TextStyle(color: Colors.white, fontSize: 20),
  145. )
  146. ],
  147. ),
  148. );
  149. }
  150. }
  151. class TablaDetalles extends StatelessWidget {
  152. final Mesa table;
  153. const TablaDetalles({
  154. Key? key,
  155. required this.table,
  156. }) : super(key: key);
  157. @override
  158. Widget build(BuildContext context) {
  159. return Container(
  160. decoration: BoxDecoration(
  161. color: Colors.white,
  162. borderRadius: BorderRadius.circular(10),
  163. ),
  164. child: Column(
  165. crossAxisAlignment: CrossAxisAlignment.start,
  166. children: [
  167. // Encabezado del panel
  168. Container(
  169. padding: const EdgeInsets.all(16),
  170. decoration: BoxDecoration(
  171. color: table.activa! ? Colors.blue : Colors.grey,
  172. borderRadius:
  173. const BorderRadius.vertical(top: Radius.circular(10)),
  174. ),
  175. child: Row(
  176. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  177. children: [
  178. Row(
  179. children: [
  180. const Icon(Icons.table_restaurant,
  181. color: Colors.white, size: 24),
  182. const SizedBox(width: 8),
  183. Text(
  184. table.nombre ?? 'Mesa sin nombre',
  185. style: const TextStyle(
  186. color: Colors.white,
  187. fontSize: 20,
  188. fontWeight: FontWeight.bold,
  189. ),
  190. ),
  191. ],
  192. ),
  193. // Indicador de estado
  194. Container(
  195. padding:
  196. const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  197. decoration: BoxDecoration(
  198. color: Colors.white.withOpacity(0.2),
  199. borderRadius: BorderRadius.circular(20),
  200. ),
  201. child: Text(
  202. table.activa! ? 'Activa' : 'Inactiva',
  203. style: const TextStyle(
  204. color: Colors.white,
  205. fontWeight: FontWeight.bold,
  206. ),
  207. ),
  208. ),
  209. ],
  210. ),
  211. ),
  212. // Contenido de la mesa
  213. Padding(
  214. padding: const EdgeInsets.all(16),
  215. child: Column(
  216. crossAxisAlignment: CrossAxisAlignment.start,
  217. children: [
  218. Text(
  219. 'ID: ${table.id}',
  220. style: const TextStyle(fontSize: 16),
  221. ),
  222. const SizedBox(height: 8),
  223. ],
  224. ),
  225. ),
  226. ],
  227. ),
  228. );
  229. }
  230. }