home_screen.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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/custom_card.dart';
  6. import 'package:turquessa_mesas_hoster/utils/widgets/navigation_rail.dart';
  7. import '../../../utils/widgets/ordenes_card.dart';
  8. import '../../viewmodels/viewmodels.dart';
  9. class HomeScreen extends StatefulWidget {
  10. const HomeScreen({super.key});
  11. @override
  12. Formulario createState() => Formulario();
  13. }
  14. class Formulario extends State<HomeScreen> {
  15. int _selectedIndex = 0;
  16. @override
  17. void initState() {
  18. super.initState();
  19. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  20. WidgetsBinding.instance.addPostFrameCallback((_) async {
  21. Provider.of<ProductoViewModel>(context, listen: false)
  22. .sincronizarProductosYCategorias();
  23. await mesaViewModel.sincronizarMesas();
  24. await mesaViewModel.fetchLocal();
  25. });
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. final mesaViewModel = Provider.of<MesaViewModel>(context);
  30. final loginViewModel = Provider.of<LoginViewModel>(context);
  31. var _selectedIndex;
  32. return Scaffold(
  33. backgroundColor: Colors.grey.shade200,
  34. appBar: AppBar(
  35. title: const CustomAppbar(),
  36. ),
  37. body: Container(
  38. decoration: const BoxDecoration(
  39. gradient: LinearGradient(
  40. begin: Alignment.topCenter,
  41. end: Alignment.bottomCenter,
  42. colors: [
  43. Color(0xFFE0F7FA),
  44. Color(0xFFB2EBF2),
  45. Color(0xFF80DEEA),
  46. Color(0xFF4DD0E1),
  47. ],
  48. ),
  49. ),
  50. child: Row(
  51. children: [
  52. CustomNavigationRail(selectedIndex: _selectedIndex),
  53. Expanded(
  54. flex: 1,
  55. child: Center(
  56. child: Container(
  57. decoration: const BoxDecoration(
  58. color: Colors.white,
  59. ),
  60. child: GridView.builder(
  61. gridDelegate:
  62. const SliverGridDelegateWithFixedCrossAxisCount(
  63. crossAxisCount: 3,
  64. childAspectRatio: 1.0,
  65. crossAxisSpacing: 10.0,
  66. mainAxisSpacing: 10.0,
  67. ),
  68. padding: const EdgeInsets.all(10),
  69. itemCount: mesaViewModel.mesas.length,
  70. itemBuilder: (context, index) {
  71. final mesa = mesaViewModel.mesas[index];
  72. return GestureDetector(
  73. onTap: () {
  74. setState(() {
  75. mesaViewModel.selectMesa(mesa);
  76. });
  77. },
  78. child: TableCard(
  79. mesa: mesa,
  80. ),
  81. );
  82. },
  83. ),
  84. ),
  85. ),
  86. ),
  87. if (mesaViewModel.selectedMesa != null)
  88. Expanded(
  89. child: Container(
  90. margin: const EdgeInsets.symmetric(horizontal: 10),
  91. decoration: BoxDecoration(
  92. color: Colors.white,
  93. borderRadius: BorderRadius.circular(10),
  94. boxShadow: [
  95. BoxShadow(
  96. color: Colors.grey.withOpacity(0.2),
  97. blurRadius: 5,
  98. spreadRadius: 1,
  99. )
  100. ],
  101. ),
  102. child: TablaDetalles(
  103. status: EstadoPedido.disponible,
  104. table: mesaViewModel.selectedMesa ??
  105. Mesa(
  106. activa: false,
  107. id: 0,
  108. nombre: 'Mesa sin nombre',
  109. estado: EstadoPedido.disponible)),
  110. )),
  111. ],
  112. ),
  113. ),
  114. );
  115. }
  116. }
  117. class TablaDetalles extends StatelessWidget {
  118. final Mesa table;
  119. final EstadoPedido status;
  120. const TablaDetalles({
  121. Key? key,
  122. required this.table,
  123. required this.status,
  124. }) : super(key: key);
  125. @override
  126. Widget build(BuildContext context) {
  127. return Container(
  128. padding: const EdgeInsets.all(10),
  129. decoration: BoxDecoration(
  130. color: Colors.white,
  131. boxShadow: [
  132. BoxShadow(
  133. color: Colors.grey.withOpacity(0.2),
  134. blurRadius: 5,
  135. spreadRadius: 1,
  136. )
  137. ],
  138. ),
  139. child: Column(
  140. children: [
  141. // Header
  142. Container(
  143. padding: const EdgeInsets.all(16),
  144. decoration: BoxDecoration(
  145. color: table.activa! ? Colors.blue : Colors.grey,
  146. borderRadius:
  147. const BorderRadius.vertical(top: Radius.circular(10)),
  148. ),
  149. child: Row(
  150. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  151. children: [
  152. Row(
  153. children: [
  154. const Icon(Icons.table_restaurant,
  155. color: Colors.white, size: 24),
  156. const SizedBox(width: 8),
  157. Column(
  158. crossAxisAlignment: CrossAxisAlignment.start,
  159. children: [
  160. Text(
  161. table.nombre ?? 'Mesa sin nombre',
  162. style: const TextStyle(
  163. color: Colors.white,
  164. fontSize: 20,
  165. fontWeight: FontWeight.bold,
  166. ),
  167. ),
  168. const Row(
  169. crossAxisAlignment: CrossAxisAlignment.center,
  170. mainAxisSize: MainAxisSize.min,
  171. children: [
  172. Icon(
  173. Icons.access_time_rounded,
  174. color: Colors.white70,
  175. size: 16,
  176. ),
  177. Padding(
  178. padding: EdgeInsets.only(left: 4),
  179. child: Text(
  180. "03:56",
  181. style: TextStyle(
  182. fontSize: 14,
  183. color: Colors.white,
  184. fontWeight: FontWeight.normal,
  185. ),
  186. ),
  187. ),
  188. ],
  189. )
  190. ],
  191. ),
  192. ],
  193. ),
  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(table.activa! ? 'Activa' : 'Inactiva',
  202. style: const TextStyle(
  203. color: Colors.white,
  204. fontWeight: FontWeight.bold,
  205. )),
  206. ),
  207. ],
  208. ),
  209. ),
  210. Expanded(
  211. child: SingleChildScrollView(
  212. child: Padding(
  213. padding: const EdgeInsets.symmetric(horizontal: 10),
  214. child: Column(
  215. crossAxisAlignment: CrossAxisAlignment.start,
  216. children: [
  217. Row(
  218. children: [
  219. Text(
  220. "Estatus: ${status.toString().split('.').last}",
  221. style: const TextStyle(
  222. fontWeight: FontWeight.bold,
  223. color: Colors.black,
  224. ),
  225. ),
  226. ],
  227. ),
  228. // const SizedBox(height: 16),
  229. // IconDataByStatus(status: status),
  230. const SizedBox(height: 16),
  231. Container(
  232. padding: const EdgeInsets.all(16),
  233. decoration: BoxDecoration(
  234. color: Colors.white,
  235. boxShadow: [
  236. BoxShadow(
  237. color: Colors.grey.withOpacity(0.2),
  238. blurRadius: 1,
  239. spreadRadius: 1,
  240. )
  241. ],
  242. borderRadius: BorderRadius.circular(10),
  243. border: Border.all(color: Colors.grey.shade200),
  244. ),
  245. child: Column(children: [
  246. Row(
  247. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  248. children: [
  249. const Text("Pedido Actual",
  250. style: TextStyle(
  251. fontWeight: FontWeight.bold,
  252. color: Colors.black,
  253. )),
  254. GestureDetector(
  255. onTap: () {
  256. Navigator.of(context)
  257. .pushNamed('creacion-pedido');
  258. },
  259. child: const Row(children: [
  260. const Text("Ver detalle"),
  261. const Icon(Icons.arrow_forward_ios_rounded),
  262. ]),
  263. )
  264. ]),
  265. const SizedBox(height: 10),
  266. const CustomProductCard(
  267. titulo: "Original Cheesse Meat burger with Chips",
  268. precio: "15.20",
  269. cantidad: 1,
  270. ),
  271. const SizedBox(height: 10),
  272. const CustomProductCard(
  273. titulo: "Original Cheesse Meat burger with Chips",
  274. precio: "15.20",
  275. cantidad: 1,
  276. ),
  277. const SizedBox(height: 10),
  278. const CustomProductCard(
  279. titulo: "Original Cheesse Meat burger with Chips",
  280. precio: "15.20",
  281. cantidad: 1,
  282. ),
  283. ]),
  284. ),
  285. //? const OrdenesScreen(),
  286. ],
  287. ),
  288. ),
  289. ),
  290. ),
  291. ],
  292. ),
  293. );
  294. }
  295. }
  296. class TableCard extends StatelessWidget {
  297. final Mesa mesa;
  298. const TableCard({
  299. super.key,
  300. required this.mesa,
  301. });
  302. @override
  303. Widget build(BuildContext context) {
  304. final status = mesa.estado ?? EstadoPedido.disponible;
  305. Color backgroundColor;
  306. Color iconColor;
  307. IconData icon;
  308. Color cardColor;
  309. switch (status) {
  310. case EstadoPedido.disponible:
  311. backgroundColor = const Color.fromARGB(255, 220, 252, 232);
  312. iconColor = Colors.green;
  313. icon = Icons.table_restaurant_rounded;
  314. cardColor = const Color.fromARGB(255, 220, 252, 232);
  315. break;
  316. case EstadoPedido.surtida:
  317. backgroundColor = const Color.fromARGB(255, 220, 234, 254);
  318. iconColor = Colors.blue;
  319. icon = Icons.coffee_rounded;
  320. cardColor = const Color.fromARGB(255, 220, 234, 254);
  321. break;
  322. case EstadoPedido.preparacion:
  323. backgroundColor = const Color.fromARGB(255, 243, 232, 255);
  324. iconColor = Colors.deepPurple;
  325. icon = Icons.kitchen_rounded;
  326. cardColor = const Color.fromARGB(255, 243, 232, 255);
  327. break;
  328. case EstadoPedido.cobrado:
  329. backgroundColor = const Color.fromARGB(255, 255, 238, 213);
  330. iconColor = Colors.amber;
  331. icon = Icons.attach_money_rounded;
  332. cardColor = const Color.fromARGB(255, 255, 238, 213);
  333. break;
  334. default:
  335. backgroundColor = Colors.grey.shade200;
  336. iconColor = Colors.grey;
  337. icon = Icons.settings;
  338. cardColor = Colors.white;
  339. break;
  340. }
  341. return Card(
  342. color: cardColor,
  343. child: Column(
  344. mainAxisAlignment: MainAxisAlignment.center,
  345. children: [
  346. IconButton(
  347. onPressed: () {
  348. if (status == EstadoPedido.disponible) {
  349. final mesaViewModel =
  350. Provider.of<MesaViewModel>(context, listen: false);
  351. mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
  352. }
  353. },
  354. iconSize: 48,
  355. style: ButtonStyle(
  356. backgroundColor: MaterialStateProperty.all(backgroundColor),
  357. ),
  358. icon: Icon(icon, color: iconColor),
  359. ),
  360. const SizedBox(height: 8),
  361. Text(
  362. mesa.nombre ?? 'Mesa sin nombre',
  363. style: TextStyle(
  364. color: status == EstadoPedido.disponible
  365. ? Colors.black
  366. : Colors.black87,
  367. fontSize: 20,
  368. fontWeight: FontWeight.w500,
  369. ),
  370. )
  371. ],
  372. ),
  373. );
  374. }
  375. }