home_screen.dart 9.2 KB

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