home_screen.dart 11 KB

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