home_screen.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. child: Container(
  98. margin: const EdgeInsets.all(10),
  99. decoration: BoxDecoration(
  100. color: Colors.white,
  101. borderRadius: BorderRadius.circular(10),
  102. boxShadow: [
  103. BoxShadow(
  104. color: Colors.grey.withOpacity(0.2),
  105. blurRadius: 5,
  106. spreadRadius: 1,
  107. )
  108. ],
  109. ),
  110. child: TablaDetalles(
  111. status: EstadoPedido.disponible,
  112. table: mesaViewModel.selectedMesa ??
  113. Mesa(
  114. activa: false,
  115. id: 0,
  116. nombre: 'Mesa sin nombre',
  117. estado: EstadoPedido.disponible)),
  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 TablaDetalles extends StatelessWidget {
  155. final Mesa table;
  156. final EstadoPedido status;
  157. const TablaDetalles({
  158. Key? key,
  159. required this.table,
  160. required this.status,
  161. }) : super(key: key);
  162. @override
  163. Widget build(BuildContext context) {
  164. return Container(
  165. margin: const EdgeInsets.all(10),
  166. decoration: BoxDecoration(
  167. color: Colors.white,
  168. borderRadius: BorderRadius.circular(10),
  169. boxShadow: [
  170. BoxShadow(
  171. color: Colors.grey.withOpacity(0.2),
  172. blurRadius: 5,
  173. spreadRadius: 1,
  174. )
  175. ],
  176. ),
  177. child: Column(
  178. children: [
  179. // Header
  180. Container(
  181. padding: const EdgeInsets.all(16),
  182. decoration: BoxDecoration(
  183. color: table.activa! ? Colors.blue : Colors.grey,
  184. borderRadius:
  185. const BorderRadius.vertical(top: Radius.circular(10)),
  186. ),
  187. child: Row(
  188. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  189. children: [
  190. Row(
  191. children: [
  192. const Icon(Icons.table_restaurant,
  193. color: Colors.white, size: 24),
  194. const SizedBox(width: 8),
  195. Text(
  196. table.nombre ?? 'Mesa sin nombre',
  197. style: const TextStyle(
  198. color: Colors.white,
  199. fontSize: 20,
  200. fontWeight: FontWeight.bold,
  201. ),
  202. ),
  203. ],
  204. ),
  205. Container(
  206. padding:
  207. const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  208. decoration: BoxDecoration(
  209. color: Colors.white.withOpacity(0.2),
  210. borderRadius: BorderRadius.circular(20),
  211. ),
  212. child: Text(
  213. table.activa! ? 'Activa' : 'Inactiva',
  214. style: const TextStyle(
  215. color: Colors.white,
  216. fontWeight: FontWeight.bold,
  217. ),
  218. ),
  219. ),
  220. ],
  221. ),
  222. ),
  223. // Contenido scrolleable
  224. Expanded(
  225. child: SingleChildScrollView(
  226. child: Padding(
  227. padding: const EdgeInsets.all(16),
  228. child: Column(
  229. crossAxisAlignment: CrossAxisAlignment.start,
  230. children: [
  231. Text(
  232. 'ID: ${table.id}',
  233. style: const TextStyle(fontSize: 16),
  234. ),
  235. const SizedBox(height: 16),
  236. Row(
  237. children: [
  238. const Text('Estado: '),
  239. Text(
  240. status.toString().split('.').last,
  241. style: const TextStyle(
  242. fontWeight: FontWeight.bold,
  243. color: Colors.blue,
  244. ),
  245. ),
  246. ],
  247. ),
  248. const SizedBox(height: 16),
  249. IconDataByStatus(status: status),
  250. const SizedBox(height: 16),
  251. const OrdenesScreen(),
  252. ],
  253. ),
  254. ),
  255. ),
  256. ),
  257. ],
  258. ),
  259. );
  260. }
  261. }
  262. class IconDataByStatus extends StatelessWidget {
  263. final EstadoPedido status;
  264. const IconDataByStatus({Key? key, required this.status});
  265. @override
  266. Widget build(BuildContext context) {
  267. switch (status) {
  268. case EstadoPedido.disponible:
  269. return IconButton(
  270. onPressed: () {
  271. final mesaViewModel =
  272. Provider.of<MesaViewModel>(context, listen: false);
  273. mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
  274. },
  275. style: ButtonStyle(
  276. backgroundColor: MaterialStateProperty.all(
  277. const Color.fromARGB(255, 220, 252, 232)),
  278. ),
  279. icon: const Icon(Icons.table_restaurant_rounded, color: Colors.green),
  280. );
  281. case EstadoPedido.surtida:
  282. return IconButton(
  283. onPressed: () {},
  284. icon: const Icon(Icons.coffee_rounded,
  285. color: Color.fromARGB(255, 220, 234, 254)),
  286. );
  287. case EstadoPedido.preparacion:
  288. return IconButton(
  289. onPressed: () {},
  290. icon: const Icon(Icons.kitchen_rounded,
  291. color: Color.fromARGB(255, 243, 232, 255)),
  292. );
  293. case EstadoPedido.cobrado:
  294. return IconButton(
  295. onPressed: () {},
  296. icon: const Icon(Icons.money_rounded,
  297. color: Color.fromARGB(255, 255, 238, 213)),
  298. );
  299. default:
  300. return IconButton(
  301. onPressed: () {},
  302. icon: const Icon(Icons.check_circle, color: Colors.grey),
  303. );
  304. }
  305. }
  306. }