home_screen.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 '../../../utils/widgets/ordenes_card.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. status: EstadoPedido.disponible,
  113. table: mesaViewModel.selectedMesa ??
  114. Mesa(
  115. activa: false,
  116. id: 0,
  117. nombre: 'Mesa sin nombre',
  118. estado: EstadoPedido.disponible)),
  119. )),
  120. ],
  121. ),
  122. );
  123. }
  124. }
  125. class TableCard extends StatelessWidget {
  126. final IconData icon;
  127. final Color color;
  128. final String title;
  129. const TableCard(
  130. {super.key,
  131. required this.icon,
  132. required this.color,
  133. required this.title});
  134. @override
  135. Widget build(BuildContext context) {
  136. return Card(
  137. color: color,
  138. child: Column(
  139. mainAxisAlignment: MainAxisAlignment.center,
  140. children: [
  141. Icon(
  142. icon,
  143. size: 50,
  144. color: Colors.white,
  145. ),
  146. Text(
  147. title,
  148. style: const TextStyle(color: Colors.white, fontSize: 20),
  149. )
  150. ],
  151. ),
  152. );
  153. }
  154. }
  155. class TablaDetalles extends StatelessWidget {
  156. final Mesa table;
  157. final EstadoPedido status;
  158. const TablaDetalles({
  159. Key? key,
  160. required this.table,
  161. required this.status,
  162. }) : super(key: key);
  163. @override
  164. Widget build(BuildContext context) {
  165. return Container(
  166. decoration: BoxDecoration(
  167. color: Colors.white,
  168. borderRadius: BorderRadius.circular(10),
  169. ),
  170. child: Column(
  171. crossAxisAlignment: CrossAxisAlignment.start,
  172. children: [
  173. // Encabezado del panel
  174. Container(
  175. padding: const EdgeInsets.all(16),
  176. decoration: BoxDecoration(
  177. color: table.activa! ? Colors.blue : Colors.grey,
  178. borderRadius:
  179. const BorderRadius.vertical(top: Radius.circular(10)),
  180. ),
  181. child: Row(
  182. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  183. children: [
  184. Row(
  185. children: [
  186. const Icon(Icons.table_restaurant,
  187. color: Colors.white, size: 24),
  188. const SizedBox(width: 8),
  189. Text(
  190. table.nombre ?? 'Mesa sin nombre',
  191. style: const TextStyle(
  192. color: Colors.white,
  193. fontSize: 20,
  194. fontWeight: FontWeight.bold,
  195. ),
  196. ),
  197. ],
  198. ),
  199. Container(
  200. padding:
  201. const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  202. decoration: BoxDecoration(
  203. color: Colors.white.withOpacity(0.2),
  204. borderRadius: BorderRadius.circular(20),
  205. ),
  206. child: Text(
  207. table.activa! ? 'Activa' : 'Inactiva',
  208. style: const TextStyle(
  209. color: Colors.white,
  210. fontWeight: FontWeight.bold,
  211. ),
  212. ),
  213. ),
  214. ],
  215. ),
  216. ),
  217. Padding(
  218. padding: const EdgeInsets.all(16),
  219. child: Column(
  220. crossAxisAlignment: CrossAxisAlignment.start,
  221. children: [
  222. Text(
  223. 'ID: ${table.id}',
  224. style: const TextStyle(fontSize: 16),
  225. ),
  226. const SizedBox(height: 8),
  227. SizedBox(
  228. height: 50,
  229. child: Row(
  230. children: [
  231. const Text('Estado: '),
  232. Text(
  233. status.toString().split('.').last,
  234. style: const TextStyle(
  235. fontWeight: FontWeight.bold,
  236. color: Colors.blue,
  237. ),
  238. ),
  239. ],
  240. ),
  241. ),
  242. const SizedBox(height: 8),
  243. // Row(
  244. // children: [
  245. // SizedBox(
  246. // height: 80,
  247. // width: 80,
  248. // child: IconDataByStatus(status: status),
  249. // )
  250. // ],
  251. // ),
  252. // // OrdenMesaCard(mesaNumero: table.nombre!, ordenNumero: table.posicion!,),
  253. // Container(
  254. // // child: OrdenesScreen(),
  255. // )
  256. ],
  257. ),
  258. ),
  259. ],
  260. ),
  261. );
  262. }
  263. }
  264. class IconDataByStatus extends StatelessWidget {
  265. final EstadoPedido status;
  266. const IconDataByStatus({Key? key, required this.status});
  267. @override
  268. Widget build(BuildContext context) {
  269. switch (status) {
  270. case EstadoPedido.disponible:
  271. return IconButton(
  272. onPressed: () {
  273. final mesaViewModel =
  274. Provider.of<MesaViewModel>(context, listen: false);
  275. mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
  276. },
  277. style: ButtonStyle(
  278. backgroundColor: MaterialStateProperty.all(
  279. const Color.fromARGB(255, 220, 252, 232)),
  280. ),
  281. icon: const Icon(Icons.table_restaurant_rounded, color: Colors.green),
  282. );
  283. case EstadoPedido.surtida:
  284. return IconButton(
  285. onPressed: () {},
  286. icon: const Icon(Icons.coffee_rounded,
  287. color: Color.fromARGB(255, 220, 234, 254)),
  288. );
  289. case EstadoPedido.preparacion:
  290. return IconButton(
  291. onPressed: () {},
  292. icon: const Icon(Icons.kitchen_rounded,
  293. color: Color.fromARGB(255, 243, 232, 255)),
  294. );
  295. case EstadoPedido.cobrado:
  296. return IconButton(
  297. onPressed: () {},
  298. icon: const Icon(Icons.money_rounded,
  299. color: Color.fromARGB(255, 255, 238, 213)),
  300. );
  301. default:
  302. return IconButton(
  303. onPressed: () {},
  304. icon: const Icon(Icons.check_circle, color: Colors.grey),
  305. );
  306. }
  307. }
  308. }