home_screen.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. decoration: BoxDecoration(
  129. color: Color.fromARGB(255, 247, 249, 250),
  130. boxShadow: [
  131. BoxShadow(
  132. color: Colors.grey.withOpacity(0.2),
  133. blurRadius: 5,
  134. spreadRadius: 1,
  135. )
  136. ],
  137. ),
  138. child: Column(
  139. children: [
  140. // Header
  141. Container(
  142. padding: const EdgeInsets.all(16),
  143. decoration: BoxDecoration(
  144. color: table.activa! ? Colors.blue : Colors.grey,
  145. ),
  146. child: Row(
  147. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  148. children: [
  149. Row(
  150. children: [
  151. const Icon(Icons.table_restaurant,
  152. color: Colors.white, size: 24),
  153. const SizedBox(width: 8),
  154. Column(
  155. crossAxisAlignment: CrossAxisAlignment.start,
  156. children: [
  157. Text(
  158. table.nombre ?? 'Mesa sin nombre',
  159. style: const TextStyle(
  160. color: Colors.white,
  161. fontSize: 20,
  162. fontWeight: FontWeight.bold,
  163. ),
  164. ),
  165. const Row(
  166. crossAxisAlignment: CrossAxisAlignment.center,
  167. mainAxisSize: MainAxisSize.min,
  168. children: [
  169. Icon(
  170. Icons.access_time_rounded,
  171. color: Colors.white70,
  172. size: 16,
  173. ),
  174. Padding(
  175. padding: EdgeInsets.only(left: 4),
  176. child: Text(
  177. "03:56",
  178. style: TextStyle(
  179. fontSize: 14,
  180. color: Colors.white,
  181. fontWeight: FontWeight.normal,
  182. ),
  183. ),
  184. ),
  185. ],
  186. )
  187. ],
  188. ),
  189. ],
  190. ),
  191. Container(
  192. padding:
  193. const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  194. decoration: BoxDecoration(
  195. color: Colors.white.withOpacity(0.2),
  196. borderRadius: BorderRadius.circular(20),
  197. ),
  198. child: Text(table.activa! ? 'Activa' : 'Inactiva',
  199. style: const TextStyle(
  200. color: Colors.white,
  201. fontWeight: FontWeight.bold,
  202. )),
  203. ),
  204. ],
  205. ),
  206. ),
  207. Expanded(
  208. child: SingleChildScrollView(
  209. child: Padding(
  210. padding: const EdgeInsets.symmetric(horizontal: 10),
  211. child: Column(
  212. crossAxisAlignment: CrossAxisAlignment.start,
  213. children: [
  214. Row(
  215. children: [
  216. // Text(
  217. // "Estatus: ${status.toString().split('.').last}",
  218. // style: const TextStyle(
  219. // fontWeight: FontWeight.bold,
  220. // color: Colors.black,
  221. // ),
  222. // ),
  223. ],
  224. ),
  225. // const SizedBox(height: 16),
  226. // IconDataByStatus(status: status),
  227. const SizedBox(height: 16),
  228. Container(
  229. padding: const EdgeInsets.all(16),
  230. decoration: BoxDecoration(
  231. color: Colors.white,
  232. borderRadius: BorderRadius.circular(10),
  233. border: Border.all(color: Colors.grey.shade200),
  234. ),
  235. child: Column(children: [
  236. Row(
  237. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  238. children: [
  239. const Text("Pedido Actual",
  240. style: TextStyle(
  241. fontWeight: FontWeight.bold,
  242. fontSize: 20,
  243. color: Colors.black,
  244. )),
  245. GestureDetector(
  246. onTap: () {
  247. Navigator.of(context)
  248. .pushNamed('creacion-pedido');
  249. },
  250. child: const Row(children: [
  251. Text("Ver detalle"),
  252. Icon(Icons.arrow_forward_ios_rounded),
  253. ]),
  254. )
  255. ]),
  256. const SizedBox(height: 10),
  257. const CustomProductCard(
  258. titulo: "Original Cheesse Meat burger with Chips",
  259. precio: "15.20",
  260. cantidad: 1,
  261. ),
  262. const SizedBox(height: 10),
  263. const CustomProductCard(
  264. titulo: "Original Cheesse Meat burger with Chips",
  265. precio: "15.20",
  266. cantidad: 1,
  267. ),
  268. const SizedBox(height: 10),
  269. const CustomProductCard(
  270. titulo: "Original Cheesse Meat burger with Chips",
  271. precio: "15.20",
  272. cantidad: 1,
  273. ),
  274. const SizedBox(height: 10),
  275. const Divider(),
  276. const Row(
  277. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  278. children: [
  279. Text(
  280. "Total",
  281. style: TextStyle(
  282. fontSize: 20, fontWeight: FontWeight.bold),
  283. ),
  284. Text(
  285. "\$45.60",
  286. style: TextStyle(
  287. fontSize: 20, fontWeight: FontWeight.bold),
  288. ),
  289. ],
  290. )
  291. ]),
  292. ),
  293. //? const OrdenesScreen(),
  294. ],
  295. ),
  296. ),
  297. ),
  298. ),
  299. ],
  300. ),
  301. );
  302. }
  303. }
  304. class TableCard extends StatelessWidget {
  305. final Mesa mesa;
  306. const TableCard({
  307. super.key,
  308. required this.mesa,
  309. });
  310. @override
  311. Widget build(BuildContext context) {
  312. final status = mesa.estado ?? EstadoPedido.disponible;
  313. Color backgroundColor;
  314. Color iconColor;
  315. IconData icon;
  316. Color cardColor;
  317. switch (status) {
  318. case EstadoPedido.disponible:
  319. backgroundColor = const Color.fromARGB(255, 220, 252, 232);
  320. iconColor = Colors.green;
  321. icon = Icons.table_restaurant_rounded;
  322. cardColor = const Color.fromARGB(255, 220, 252, 232);
  323. break;
  324. case EstadoPedido.surtida:
  325. backgroundColor = const Color.fromARGB(255, 220, 234, 254);
  326. iconColor = Colors.blue;
  327. icon = Icons.coffee_rounded;
  328. cardColor = const Color.fromARGB(255, 220, 234, 254);
  329. break;
  330. case EstadoPedido.preparacion:
  331. backgroundColor = const Color.fromARGB(255, 243, 232, 255);
  332. iconColor = Colors.deepPurple;
  333. icon = Icons.restaurant_rounded;
  334. cardColor = Colors.white;
  335. // cardColor = const Color.fromARGB(255, 243, 232, 255);
  336. break;
  337. case EstadoPedido.cobrado:
  338. backgroundColor = const Color.fromARGB(255, 255, 238, 213);
  339. iconColor = Colors.amber;
  340. icon = Icons.attach_money_rounded;
  341. cardColor = Colors.white;
  342. // cardColor = const Color.fromARGB(255, 255, 238, 213);
  343. break;
  344. default:
  345. backgroundColor = Colors.grey.shade200;
  346. iconColor = Colors.grey;
  347. icon = Icons.settings;
  348. cardColor = Colors.white;
  349. break;
  350. }
  351. return Card(
  352. borderOnForeground: false,
  353. color: cardColor,
  354. child: Column(
  355. mainAxisAlignment: MainAxisAlignment.center,
  356. children: [
  357. IconButton(
  358. onPressed: () {
  359. if (status == EstadoPedido.disponible) {
  360. final mesaViewModel =
  361. Provider.of<MesaViewModel>(context, listen: false);
  362. mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
  363. }
  364. },
  365. iconSize: 48,
  366. style: ButtonStyle(
  367. backgroundColor: MaterialStateProperty.all(backgroundColor),
  368. ),
  369. icon: Icon(icon, color: iconColor),
  370. ),
  371. const SizedBox(height: 8),
  372. Text(
  373. mesa.nombre ?? 'Mesa sin nombre',
  374. style: TextStyle(
  375. color: status == EstadoPedido.disponible
  376. ? Colors.black
  377. : Colors.black87,
  378. fontSize: 20,
  379. fontWeight: FontWeight.w500,
  380. ),
  381. ),
  382. Container(
  383. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  384. decoration: BoxDecoration(
  385. color: backgroundColor,
  386. borderRadius: BorderRadius.circular(20),
  387. ),
  388. child: Text(status.toString().split('.').last,
  389. style: TextStyle(
  390. color: iconColor,
  391. fontWeight: FontWeight.bold,
  392. )),
  393. )
  394. ],
  395. ),
  396. );
  397. }
  398. }