home_screen.dart 13 KB

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