home_screen.dart 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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/utils/widgets/navigation_rail.dart';
  6. import '../../../utils/widgets/ordenes_card.dart';
  7. import '../../viewmodels/viewmodels.dart';
  8. class HomeScreen extends StatefulWidget {
  9. const HomeScreen({super.key});
  10. @override
  11. Formulario createState() => Formulario();
  12. }
  13. class Formulario extends State<HomeScreen> {
  14. int _selectedIndex = 0;
  15. @override
  16. void initState() {
  17. super.initState();
  18. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  19. WidgetsBinding.instance.addPostFrameCallback((_) async {
  20. Provider.of<ProductoViewModel>(context, listen: false)
  21. .sincronizarProductosYCategorias();
  22. await mesaViewModel.sincronizarMesas();
  23. await mesaViewModel.fetchLocal();
  24. });
  25. }
  26. @override
  27. Widget build(BuildContext context) {
  28. final mesaViewModel = Provider.of<MesaViewModel>(context);
  29. final loginViewModel = Provider.of<LoginViewModel>(context);
  30. var _selectedIndex;
  31. return Scaffold(
  32. backgroundColor: Colors.grey.shade200,
  33. appBar: AppBar(
  34. title: const CustomAppbar(),
  35. ),
  36. body: Row(
  37. children: [
  38. CustomNavigationRail(selectedIndex: _selectedIndex),
  39. Expanded(
  40. child: Center(
  41. child: GridView.builder(
  42. gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
  43. crossAxisCount: 4,
  44. childAspectRatio: 1.0,
  45. crossAxisSpacing: 10.0,
  46. mainAxisSpacing: 10.0,
  47. ),
  48. padding: const EdgeInsets.all(10),
  49. itemCount: mesaViewModel.mesas.length,
  50. itemBuilder: (context, index) {
  51. final mesa = mesaViewModel.mesas[index];
  52. return GestureDetector(
  53. onTap: () {
  54. setState(() {
  55. mesaViewModel.selectMesa(mesa);
  56. });
  57. },
  58. child: TableCard(
  59. mesa: mesa,
  60. ),
  61. );
  62. },
  63. ),
  64. ),
  65. ),
  66. if (mesaViewModel.selectedMesa != null)
  67. Expanded(
  68. child: Container(
  69. margin: const EdgeInsets.all(10),
  70. decoration: BoxDecoration(
  71. color: Colors.white,
  72. borderRadius: BorderRadius.circular(10),
  73. boxShadow: [
  74. BoxShadow(
  75. color: Colors.grey.withOpacity(0.2),
  76. blurRadius: 5,
  77. spreadRadius: 1,
  78. )
  79. ],
  80. ),
  81. child: TablaDetalles(
  82. status: EstadoPedido.disponible,
  83. table: mesaViewModel.selectedMesa ??
  84. Mesa(
  85. activa: false,
  86. id: 0,
  87. nombre: 'Mesa sin nombre',
  88. estado: EstadoPedido.disponible)),
  89. )),
  90. ],
  91. ),
  92. );
  93. }
  94. }
  95. class TablaDetalles extends StatelessWidget {
  96. final Mesa table;
  97. final EstadoPedido status;
  98. const TablaDetalles({
  99. Key? key,
  100. required this.table,
  101. required this.status,
  102. }) : super(key: key);
  103. @override
  104. Widget build(BuildContext context) {
  105. return Container(
  106. margin: const EdgeInsets.all(10),
  107. decoration: BoxDecoration(
  108. color: Colors.white,
  109. borderRadius: BorderRadius.circular(10),
  110. boxShadow: [
  111. BoxShadow(
  112. color: Colors.grey.withOpacity(0.2),
  113. blurRadius: 5,
  114. spreadRadius: 1,
  115. )
  116. ],
  117. ),
  118. child: Column(
  119. children: [
  120. // Header
  121. Container(
  122. padding: const EdgeInsets.all(16),
  123. decoration: BoxDecoration(
  124. color: table.activa! ? Colors.blue : Colors.grey,
  125. borderRadius:
  126. const BorderRadius.vertical(top: Radius.circular(10)),
  127. ),
  128. child: Row(
  129. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  130. children: [
  131. Row(
  132. children: [
  133. const Icon(Icons.table_restaurant,
  134. color: Colors.white, size: 24),
  135. const SizedBox(width: 8),
  136. Text(
  137. table.nombre ?? 'Mesa sin nombre',
  138. style: const TextStyle(
  139. color: Colors.white,
  140. fontSize: 20,
  141. fontWeight: FontWeight.bold,
  142. ),
  143. ),
  144. ],
  145. ),
  146. Container(
  147. padding:
  148. const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  149. decoration: BoxDecoration(
  150. color: Colors.white.withOpacity(0.2),
  151. borderRadius: BorderRadius.circular(20),
  152. ),
  153. child: Text(
  154. table.activa! ? 'Activa' : 'Inactiva',
  155. style: const TextStyle(
  156. color: Colors.white,
  157. fontWeight: FontWeight.bold,
  158. ),
  159. ),
  160. ),
  161. ],
  162. ),
  163. ),
  164. // Contenido scrolleable
  165. Expanded(
  166. child: SingleChildScrollView(
  167. child: Padding(
  168. padding: const EdgeInsets.all(16),
  169. child: Column(
  170. crossAxisAlignment: CrossAxisAlignment.start,
  171. children: [
  172. Text(
  173. 'ID: ${table.id}',
  174. style: const TextStyle(fontSize: 16),
  175. ),
  176. const SizedBox(height: 16),
  177. Row(
  178. children: [
  179. const Text('Estado: '),
  180. Text(
  181. status.toString().split('.').last,
  182. style: const TextStyle(
  183. fontWeight: FontWeight.bold,
  184. color: Colors.blue,
  185. ),
  186. ),
  187. ],
  188. ),
  189. const SizedBox(height: 16),
  190. // IconDataByStatus(status: status),
  191. const SizedBox(height: 16),
  192. OrdenesScreen(),
  193. ],
  194. ),
  195. ),
  196. ),
  197. ),
  198. ],
  199. ),
  200. );
  201. }
  202. }
  203. class TableCard extends StatelessWidget {
  204. final Mesa mesa;
  205. const TableCard({
  206. super.key,
  207. required this.mesa,
  208. });
  209. @override
  210. Widget build(BuildContext context) {
  211. final status = mesa.estado ?? EstadoPedido.disponible;
  212. Color backgroundColor;
  213. Color iconColor;
  214. IconData icon;
  215. Color cardColor;
  216. switch (status) {
  217. case EstadoPedido.disponible:
  218. backgroundColor = const Color.fromARGB(255, 220, 252, 232);
  219. iconColor = Colors.green;
  220. icon = Icons.table_restaurant_rounded;
  221. cardColor = const Color.fromARGB(255, 220, 252, 232);
  222. break;
  223. case EstadoPedido.surtida:
  224. backgroundColor = const Color.fromARGB(255, 220, 234, 254);
  225. iconColor = Colors.blue;
  226. icon = Icons.coffee_rounded;
  227. cardColor = const Color.fromARGB(255, 220, 234, 254);
  228. break;
  229. case EstadoPedido.preparacion:
  230. backgroundColor = const Color.fromARGB(255, 243, 232, 255);
  231. iconColor = Colors.deepPurple;
  232. icon = Icons.kitchen_rounded;
  233. cardColor = const Color.fromARGB(255, 243, 232, 255);
  234. break;
  235. case EstadoPedido.cobrado:
  236. backgroundColor = const Color.fromARGB(255, 255, 238, 213);
  237. iconColor = Colors.amber;
  238. icon = Icons.attach_money_rounded;
  239. cardColor = const Color.fromARGB(255, 255, 238, 213);
  240. break;
  241. default:
  242. backgroundColor = Colors.grey.shade200;
  243. iconColor = Colors.grey;
  244. icon = Icons.settings;
  245. cardColor = Colors.white;
  246. break;
  247. }
  248. return Card(
  249. color: cardColor,
  250. child: Column(
  251. mainAxisAlignment: MainAxisAlignment.center,
  252. children: [
  253. IconButton(
  254. onPressed: () {
  255. if (status == EstadoPedido.disponible) {
  256. final mesaViewModel =
  257. Provider.of<MesaViewModel>(context, listen: false);
  258. mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
  259. }
  260. },
  261. iconSize: 48,
  262. style: ButtonStyle(
  263. backgroundColor: MaterialStateProperty.all(backgroundColor),
  264. ),
  265. icon: Icon(icon, color: iconColor),
  266. ),
  267. const SizedBox(height: 8),
  268. Text(
  269. mesa.nombre ?? 'Mesa sin nombre',
  270. style: TextStyle(
  271. color: status == EstadoPedido.disponible
  272. ? Colors.black
  273. : Colors.black87,
  274. fontSize: 20,
  275. fontWeight: FontWeight.w500,
  276. ),
  277. )
  278. ],
  279. ),
  280. );
  281. }
  282. }