pedido_screen.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. // ignore_for_file: use_build_context_synchronously
  2. import 'package:flutter/material.dart';
  3. import 'package:yoshi_papas_app/widgets/widgets.dart';
  4. import 'package:provider/provider.dart';
  5. import 'package:intl/intl.dart';
  6. import '../../viewmodels/viewmodels.dart';
  7. import '../../models/models.dart';
  8. import '../../themes/themes.dart';
  9. import 'pedido_form.dart';
  10. import '../../services/services.dart' as servicio;
  11. class PedidoScreen extends StatefulWidget {
  12. const PedidoScreen({Key? key}) : super(key: key);
  13. @override
  14. State<PedidoScreen> createState() => Formulario();
  15. }
  16. class Formulario extends State<PedidoScreen> {
  17. final _busqueda = TextEditingController(text: '');
  18. ScrollController horizontalScrollController = ScrollController();
  19. DateTime? fechaInicio = DateTime.now();
  20. DateTime? fechaFin;
  21. Size? _size;
  22. @override
  23. void initState() {
  24. super.initState();
  25. WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
  26. // await Provider.of<PedidoViewModel>(context, listen: false)
  27. // .setIsLoading(true);
  28. // await Provider.of<PedidoViewModel>(context, listen: false)
  29. // .fetchRegistros();
  30. // List<Empresa> lasempresas =
  31. // Provider.of<EmpresaViewModel>(context, listen: false).empresas;
  32. // if (lasempresas.isNotEmpty) {
  33. // setState(() {
  34. // empresa = lasempresas.first;
  35. // });
  36. // }
  37. // await Future.delayed(const Duration(seconds: 1));
  38. // await Provider.of<OrdenesViewModel>(context, listen: false)
  39. // .setIsLoading(false);
  40. });
  41. }
  42. @override
  43. void dispose() {
  44. horizontalScrollController.dispose();
  45. super.dispose();
  46. }
  47. // go(Orden item) async {
  48. // Provider.of<CamaraViewModel>(context, listen: false).limpiarFotos();
  49. // Provider.of<MediaViewModel>(context, listen: false).limpiar();
  50. // Provider.of<OrdenesViewModel>(context, listen: false).selectOrden(item);
  51. // Navigator.push(
  52. // context,
  53. // MaterialPageRoute(
  54. // builder: (context) => const OrdenForm(),
  55. // ),
  56. // ).then((value) async {
  57. // await Provider.of<OrdenesViewModel>(context, listen: false)
  58. // .fetchRegistros();
  59. // });
  60. // }
  61. @override
  62. Widget build(BuildContext context) {
  63. //final mvm = Provider.of<PedidoViewModel>(context);
  64. double screenWidth = MediaQuery.of(context).size.width;
  65. final isMobile = screenWidth < 1250;
  66. final double? columnSpacing = isMobile ? null : 0;
  67. //final isLoading = mvm.isLoading;
  68. // if (isLoading) return const Cargando();
  69. TextStyle estilo = const TextStyle(fontWeight: FontWeight.bold);
  70. List<DataRow> registros = [];
  71. //if (mvm.registros.isNotEmpty) {
  72. var vuelta = 0;
  73. //for (Orden item in mvm.registros) {
  74. var _tipo = vuelta % 2;
  75. vuelta++;
  76. String fsalida = "";
  77. // if (item.fechaSalida != null) {
  78. // fsalida = DateFormat("dd/MM/yyyy HH:mm")
  79. // .format(item.fechaSalida!)
  80. // .toString();
  81. // }
  82. registros.add(DataRow(selected: _tipo > 0, cells: [
  83. DataCell(
  84. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  85. PopupMenuButton(
  86. surfaceTintColor: AppTheme.primary,
  87. itemBuilder: (context) => [
  88. PopupMenuItem(
  89. child: const Text('Editar'),
  90. onTap: () => {} /*go(item)*/,
  91. ),
  92. PopupMenuItem(
  93. child: const Text(
  94. 'Eliminar',
  95. ),
  96. onTap: () async {
  97. return showDialog(
  98. context: context,
  99. builder: (context) {
  100. return AlertDialog(
  101. title: const Text("Eliminar registro"),
  102. content: const Text('¿Desea eliminar el registro?'),
  103. actions: [
  104. Row(children: [
  105. Expanded(
  106. child: TextButton(
  107. onPressed: () {
  108. Navigator.pop(context);
  109. },
  110. child: const Text('Cancelar'),
  111. )),
  112. Expanded(
  113. child: TextButton(
  114. onPressed: () async {
  115. // //await mvm.eliminar(item);
  116. // await mvm.fetchRegistros();
  117. // if (context.mounted) {
  118. // Navigator.pop(context);
  119. // }
  120. },
  121. child: const Text('Continuar'),
  122. ))
  123. ])
  124. ],
  125. );
  126. },
  127. );
  128. },
  129. ),
  130. PopupMenuItem(
  131. child: const Text('Imprimir'),
  132. //onTap: () => imprimir(item),
  133. ),
  134. ],
  135. icon: const Icon(Icons.more_vert),
  136. shape:
  137. RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
  138. ),
  139. ])),
  140. DataCell(
  141. Text('Pedido'),
  142. //Text(item.folio.toString()),
  143. // onTap: () => go(item),
  144. ),
  145. DataCell(
  146. Text('Petición'),
  147. //Text(item.numeroUnidad.toString()),
  148. //onTap: () => go(item),
  149. ),
  150. DataCell(
  151. Text('Cliente'),
  152. //Text(item.nombreChofer.toString()),
  153. //onTap: () => go(item),
  154. ),
  155. DataCell(
  156. Text('Mesa'),
  157. //Text("${item.categoriaFalla.toString()}: ${item.falla.toString()}"),
  158. // onTap: () => go(item),
  159. ),
  160. DataCell(
  161. Text('Productos Terminados'),
  162. //Text(item.estatus.toString()),
  163. //onTap: () => go(item),
  164. ),
  165. DataCell(
  166. Text('Visto'),
  167. //Text(item.estatus.toString()),
  168. //onTap: () => go(item),
  169. ),
  170. ]));
  171. //}
  172. //}
  173. _size = MediaQuery.of(context).size;
  174. return Scaffold(
  175. appBar: encabezado(
  176. titulo: "PEDIDOS",
  177. ),
  178. floatingActionButton: FloatingActionButton(
  179. onPressed: () async {
  180. // Aquí asumo que quieres navegar a una nueva página cuando se presione el botón
  181. await Navigator.of(context).push(
  182. MaterialPageRoute(
  183. builder: (context) => PedidoForm(),
  184. ),
  185. );
  186. },
  187. child: const Icon(Icons
  188. .add), // Este es el hijo del FloatingActionButton, que define el ícono que se muestra en el botón.
  189. ),
  190. body: Column(
  191. children: [
  192. Expanded(
  193. child: ListView(
  194. padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
  195. children: [
  196. const SizedBox(height: 8),
  197. tarjeta(
  198. Padding(
  199. padding: const EdgeInsets.all(8.0),
  200. child: LayoutBuilder(
  201. builder: (context, constraints) {
  202. if (screenWidth > 1000) {
  203. return Row(
  204. children: [
  205. Expanded(
  206. flex: 10,
  207. child: Row(
  208. crossAxisAlignment:
  209. CrossAxisAlignment.start,
  210. children: [
  211. BusquedaTextField(),
  212. ],
  213. )),
  214. SizedBox(width: 5),
  215. BotonBuscar()
  216. ],
  217. );
  218. } else {
  219. return Column(
  220. children: [
  221. Row(
  222. children: [BusquedaTextField()],
  223. ),
  224. SizedBox(height: 10),
  225. SizedBox(height: 15),
  226. Row(
  227. children: [BotonBuscar()],
  228. ),
  229. ],
  230. );
  231. }
  232. },
  233. ),
  234. ),
  235. ),
  236. const SizedBox(height: 8),
  237. // isLoading
  238. // ? const Center(child: CircularProgressIndicator())
  239. // : Container(),
  240. tarjeta(
  241. Column(
  242. children: [
  243. LayoutBuilder(builder: (context, constraints) {
  244. return SingleChildScrollView(
  245. scrollDirection: Axis.vertical,
  246. child: Scrollbar(
  247. controller: horizontalScrollController,
  248. interactive: true,
  249. thumbVisibility: true,
  250. thickness:
  251. 10.0, // Esto es opcional para cambiar el grosor
  252. child: SingleChildScrollView(
  253. controller: horizontalScrollController,
  254. scrollDirection: Axis.horizontal,
  255. child: ConstrainedBox(
  256. constraints: BoxConstraints(
  257. minWidth: isMobile
  258. ? constraints.maxWidth
  259. : screenWidth),
  260. child: DataTable(
  261. columnSpacing: columnSpacing,
  262. sortAscending: true,
  263. sortColumnIndex: 1,
  264. columns: [
  265. DataColumn(label: Text(" ", style: estilo)),
  266. DataColumn(
  267. label: Text("PEDIDO", style: estilo)),
  268. DataColumn(
  269. label: Text("PETICIÓN", style: estilo)),
  270. DataColumn(
  271. label: Text("CLIENTE", style: estilo)),
  272. DataColumn(
  273. label: Text("MESA", style: estilo)),
  274. DataColumn(
  275. label: Text("PRODUCTOS TERMINADOS",
  276. style: estilo)),
  277. DataColumn(
  278. label: Text("VISTO", style: estilo)),
  279. ],
  280. rows: registros,
  281. ),
  282. ),
  283. ),
  284. ),
  285. );
  286. }),
  287. // PaginationButtons(
  288. // currentPage: mvm.pagina,
  289. // totalPages: mvm.totalPaginas,
  290. // onPageChanged: (i) => mvm.cambiarPagina(i,
  291. // empresa: _selectedEmpresa, falla: _selectedFalla),
  292. // )
  293. ],
  294. ),
  295. ),
  296. ],
  297. ),
  298. ),
  299. ],
  300. ),
  301. );
  302. }
  303. Widget BusquedaTextField() {
  304. return Expanded(
  305. flex: 4,
  306. child: AppTextField(
  307. prefixIcon: const Icon(Icons.search),
  308. etiqueta: 'Búsqueda por folio...',
  309. controller: _busqueda,
  310. hintText: 'Búsqueda por folio...',
  311. ),
  312. );
  313. }
  314. Widget BotonBuscar() {
  315. return Expanded(
  316. flex: 2,
  317. child: botonElevated(
  318. accion: () async {
  319. _busqueda.text = _busqueda.text.trim();
  320. /* if (_busqueda.text.isEmpty && _selectedFalla == null) {
  321. return alerta(context);
  322. } */
  323. // OrdenesViewModel mvm =
  324. // Provider.of<OrdenesViewModel>(context, listen: false);
  325. // await mvm.setIsLoading(true);
  326. // await mvm.setBusqueda(_busqueda.text);
  327. // await mvm.fetchRegistros(
  328. // falla: _selectedFalla, empresa: _selectedEmpresa);
  329. // await mvm.setBusqueda("");
  330. // await mvm.setIsLoading(false);
  331. },
  332. ),
  333. );
  334. }
  335. }