pedido_screen.dart 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. import 'package:flutter/material.dart';
  2. import 'package:intl/intl.dart';
  3. import 'package:omni_datetime_picker/omni_datetime_picker.dart';
  4. import 'package:provider/provider.dart';
  5. import '../pedido/pedido_csv.dart';
  6. import '../pedido/pedido_detalle_screen.dart';
  7. import '../../widgets/widgets.dart';
  8. import '../../themes/themes.dart';
  9. import '../../models/models.dart';
  10. import '../../viewmodels/viewmodels.dart';
  11. import '../../widgets/widgets_components.dart' as clase;
  12. import 'pedido_form.dart';
  13. import 'package:otp/otp.dart';
  14. import 'package:timezone/data/latest.dart' as timezone;
  15. import 'package:timezone/timezone.dart' as timezone;
  16. class PedidoScreen extends StatefulWidget {
  17. const PedidoScreen({Key? key}) : super(key: key);
  18. @override
  19. State<PedidoScreen> createState() => _PedidoScreenState();
  20. }
  21. class _PedidoScreenState extends State<PedidoScreen> {
  22. final _busqueda = TextEditingController(text: '');
  23. DateTime? fechaInicio;
  24. DateTime? fechaFin;
  25. ScrollController horizontalScrollController = ScrollController();
  26. TextEditingController codeController = new TextEditingController();
  27. bool _isMesasActive = false;
  28. @override
  29. void initState() {
  30. super.initState();
  31. WidgetsBinding.instance.addPostFrameCallback((_) {
  32. Provider.of<PedidoViewModel>(context, listen: false)
  33. .fetchLocalPedidosForScreen();
  34. });
  35. Future.microtask(() async {
  36. bool isMesasActive =
  37. await Provider.of<VariableViewModel>(context, listen: false)
  38. .isVariableActive('MESAS');
  39. setState(() {
  40. _isMesasActive = isMesasActive;
  41. });
  42. });
  43. }
  44. void exportCSV() async {
  45. final pedidosViewModel =
  46. Provider.of<PedidoViewModel>(context, listen: false);
  47. List<Pedido> pedidosConProductos = [];
  48. for (Pedido pedido in pedidosViewModel.pedidos) {
  49. Pedido? pedidoConProductos =
  50. await pedidosViewModel.fetchPedidoConProductos(pedido.id);
  51. if (pedidoConProductos != null) {
  52. pedidosConProductos.add(pedidoConProductos);
  53. }
  54. }
  55. if (pedidosConProductos.isNotEmpty) {
  56. String fileName = 'Pedidos_Turquessa_POS';
  57. if (fechaInicio != null && fechaFin != null) {
  58. String startDateStr = DateFormat('dd-MM-yyyy').format(fechaInicio!);
  59. String endDateStr = DateFormat('dd-MM-yyyy').format(fechaFin!);
  60. fileName += '_${startDateStr}_al_${endDateStr}';
  61. }
  62. fileName += '.csv';
  63. await exportarPedidosACSV(pedidosConProductos, fileName);
  64. ScaffoldMessenger.of(context).showSnackBar(SnackBar(
  65. content: Text('Archivo CSV descargado! Archivo: $fileName')));
  66. } else {
  67. ScaffoldMessenger.of(context).showSnackBar(
  68. SnackBar(content: Text('No hay pedidos para exportar.')));
  69. }
  70. }
  71. void clearSearchAndReset() {
  72. setState(() {
  73. _busqueda.clear();
  74. fechaInicio = null;
  75. fechaFin = null;
  76. Provider.of<PedidoViewModel>(context, listen: false)
  77. .fetchLocalPedidosForScreen();
  78. });
  79. }
  80. void go(Pedido item) async {
  81. Pedido? pedidoCompleto =
  82. await Provider.of<PedidoViewModel>(context, listen: false)
  83. .fetchPedidoConProductos(item.id);
  84. if (pedidoCompleto != null) {
  85. if (pedidoCompleto.estatus == 'TERMINADO' ||
  86. pedidoCompleto.estatus == 'CANCELADO' ||
  87. !_isMesasActive) {
  88. Navigator.push(
  89. context,
  90. MaterialPageRoute(
  91. builder: (context) => PedidoDetalleScreen(pedido: pedidoCompleto),
  92. ),
  93. );
  94. } else {
  95. Navigator.push(
  96. context,
  97. MaterialPageRoute(
  98. builder: (context) => PedidoForm(
  99. pedidoExistente: pedidoCompleto,
  100. ),
  101. ),
  102. ).then((value) async {
  103. await Provider.of<PedidoViewModel>(context, listen: false)
  104. .fetchLocalPedidosForScreen();
  105. });
  106. }
  107. } else {
  108. print("Error al cargar el pedido con productos");
  109. }
  110. }
  111. @override
  112. Widget build(BuildContext context) {
  113. final pvm = Provider.of<PedidoViewModel>(context);
  114. double screenWidth = MediaQuery.of(context).size.width;
  115. final isMobile = screenWidth < 1250;
  116. final double? columnSpacing = isMobile ? null : 0;
  117. TextStyle estilo = const TextStyle(fontWeight: FontWeight.bold);
  118. List<DataRow> registros = [];
  119. final permisoViewModel = Provider.of<PermisoViewModel>(context);
  120. List<String> userPermisos = permisoViewModel.userPermisos;
  121. for (Pedido item in pvm.pedidos) {
  122. final sincronizadoStatus =
  123. item.sincronizado == null || item.sincronizado!.isEmpty
  124. ? "No Sincronizado"
  125. : _formatDateTime(item.sincronizado);
  126. final mesaViewModel = Provider.of<MesaViewModel>(context, listen: false);
  127. final mesa = mesaViewModel.fetchLocalById(idMesa: item.idMesa);
  128. registros.add(DataRow(cells: [
  129. DataCell(
  130. Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
  131. PopupMenuButton(
  132. itemBuilder: (context) => [
  133. PopupMenuItem(
  134. child: const Text('Detalle'),
  135. onTap: () => go(item),
  136. ),
  137. if (userPermisos.contains(Usuario.CANCELAR_PEDIDO))
  138. PopupMenuItem(
  139. child: const Text('Cancelar Pedido'),
  140. onTap: () async {
  141. bool confirmado = await showDialog<bool>(
  142. context: context,
  143. builder: (context) {
  144. return AlertDialog(
  145. title: const Text("Cancelar Pedido",
  146. style: TextStyle(
  147. fontWeight: FontWeight.w500,
  148. fontSize: 22)),
  149. content: const Text(
  150. '¿Estás seguro de que deseas cancelar este pedido?',
  151. style: TextStyle(fontSize: 18)),
  152. actions: [
  153. Column(
  154. children: [
  155. Container(
  156. padding: EdgeInsets.all(8.0),
  157. child: TextField(
  158. controller: codeController,
  159. decoration: InputDecoration(
  160. label: Text(
  161. "Para cancelar debe capturar el código")),
  162. ),
  163. ),
  164. Row(
  165. mainAxisAlignment:
  166. MainAxisAlignment.spaceBetween,
  167. children: [
  168. TextButton(
  169. onPressed: () =>
  170. Navigator.of(context).pop(false),
  171. child: const Text('No',
  172. style: TextStyle(fontSize: 18)),
  173. style: ButtonStyle(
  174. padding: MaterialStatePropertyAll(
  175. EdgeInsets.fromLTRB(
  176. 20, 10, 20, 10)),
  177. backgroundColor:
  178. MaterialStatePropertyAll(
  179. Colors.red),
  180. foregroundColor:
  181. MaterialStatePropertyAll(
  182. AppTheme.secondary)),
  183. ),
  184. TextButton(
  185. onPressed: () {
  186. final now = DateTime.now().toUtc();
  187. timezone.initializeTimeZones();
  188. final pacificTimeZone =
  189. timezone.getLocation(
  190. 'America/Los_Angeles');
  191. final date =
  192. timezone.TZDateTime.from(
  193. now, pacificTimeZone);
  194. final codigoTotp =
  195. OTP.generateTOTPCodeString(
  196. 'TYSNE4CMT5LVLGWS',
  197. date.millisecondsSinceEpoch,
  198. algorithm: Algorithm.SHA1,
  199. isGoogle: true);
  200. String codigo = codeController.text;
  201. print(
  202. "totp: $codigoTotp codigo:$codigo");
  203. List<String> codigosEstaticos = [
  204. '172449',
  205. '827329',
  206. // Agregar más token fijos
  207. ];
  208. bool esCodigoEstatico =
  209. codigosEstaticos
  210. .contains(codigo);
  211. print(
  212. "¿Es código estático? ${esCodigoEstatico} ${!esCodigoEstatico && codigo != codigoTotp}");
  213. if (!esCodigoEstatico &&
  214. codigo != codigoTotp) {
  215. ScaffoldMessenger.of(context)
  216. .showSnackBar(SnackBar(
  217. content: Text(
  218. 'El código no es correcto'),
  219. duration: Duration(seconds: 2),
  220. ));
  221. return;
  222. } else {
  223. codeController.text = '';
  224. Navigator.of(context).pop(true);
  225. }
  226. },
  227. child: const Text('Sí',
  228. style: TextStyle(fontSize: 18)),
  229. style: ButtonStyle(
  230. padding: MaterialStatePropertyAll(
  231. EdgeInsets.fromLTRB(
  232. 20, 10, 20, 10)),
  233. backgroundColor:
  234. MaterialStatePropertyAll(
  235. AppTheme.tertiary),
  236. foregroundColor:
  237. MaterialStatePropertyAll(
  238. AppTheme.quaternary)),
  239. ),
  240. ],
  241. )
  242. ],
  243. ),
  244. ],
  245. );
  246. },
  247. ) ??
  248. false;
  249. if (confirmado) {
  250. await Provider.of<PedidoViewModel>(context, listen: false)
  251. .cancelarPedido(item.id);
  252. ScaffoldMessenger.of(context).showSnackBar(SnackBar(
  253. content: Text("Pedido cancelado correctamente")));
  254. }
  255. },
  256. )
  257. ],
  258. icon: const Icon(Icons.more_vert),
  259. )
  260. ])),
  261. if (_isMesasActive)
  262. DataCell(
  263. Text(mesa.nombre ?? "Mesa desconocida"),
  264. onTap: () => go(item),
  265. ),
  266. DataCell(
  267. Text(item.folio.toString()),
  268. onTap: () => go(item),
  269. ),
  270. DataCell(
  271. Text(item.nombreCliente ?? "Sin nombre"),
  272. onTap: () => go(item),
  273. ),
  274. DataCell(
  275. Text(item.comentarios ?? "Sin comentarios"),
  276. onTap: () => go(item),
  277. ),
  278. DataCell(
  279. Text(item.estatus ?? "Sin Estatus"),
  280. onTap: () => go(item),
  281. ),
  282. DataCell(
  283. Text(_formatDateTime(item.peticion)),
  284. onTap: () => go(item),
  285. ),
  286. DataCell(
  287. Text(sincronizadoStatus),
  288. onTap: () => go(item),
  289. ),
  290. ]));
  291. }
  292. return Scaffold(
  293. appBar: AppBar(
  294. title: Text(
  295. 'Pedidos',
  296. style: TextStyle(
  297. color: AppTheme.secondary, fontWeight: FontWeight.w500),
  298. ),
  299. actions: <Widget>[
  300. if (userPermisos.contains(Usuario.VER_REPORTE))
  301. IconButton(
  302. icon: const Icon(Icons.save_alt),
  303. onPressed: exportCSV,
  304. tooltip: 'Exportar a CSV',
  305. ),
  306. ],
  307. iconTheme: IconThemeData(color: AppTheme.secondary)),
  308. body: Stack(
  309. children: [
  310. Column(
  311. children: [
  312. Expanded(
  313. child: ListView(
  314. padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
  315. children: [
  316. const SizedBox(height: 8),
  317. clase.tarjeta(
  318. Padding(
  319. padding: const EdgeInsets.all(8.0),
  320. child: LayoutBuilder(
  321. builder: (context, constraints) {
  322. if (screenWidth > 1000) {
  323. return Row(
  324. crossAxisAlignment: CrossAxisAlignment.end,
  325. children: [
  326. Expanded(
  327. flex: 7,
  328. child: _buildDateRangePicker(),
  329. ),
  330. const SizedBox(width: 5),
  331. botonBuscar()
  332. ],
  333. );
  334. } else {
  335. return Column(
  336. children: [
  337. Row(
  338. children: [_buildDateRangePicker()],
  339. ),
  340. Row(
  341. children: [botonBuscar()],
  342. ),
  343. ],
  344. );
  345. }
  346. },
  347. ),
  348. ),
  349. ),
  350. const SizedBox(height: 8),
  351. pvm.isLoading
  352. ? const Center(child: CircularProgressIndicator())
  353. : Container(),
  354. clase.tarjeta(
  355. Column(
  356. children: [
  357. LayoutBuilder(builder: (context, constraints) {
  358. return SingleChildScrollView(
  359. scrollDirection: Axis.vertical,
  360. child: Scrollbar(
  361. controller: horizontalScrollController,
  362. interactive: true,
  363. thumbVisibility: true,
  364. thickness: 10.0,
  365. child: SingleChildScrollView(
  366. controller: horizontalScrollController,
  367. scrollDirection: Axis.horizontal,
  368. child: ConstrainedBox(
  369. constraints: BoxConstraints(
  370. minWidth: isMobile
  371. ? constraints.maxWidth
  372. : screenWidth),
  373. child: DataTable(
  374. columnSpacing: columnSpacing,
  375. sortAscending: true,
  376. sortColumnIndex: 1,
  377. columns: [
  378. DataColumn(
  379. label: Text(" ", style: estilo)),
  380. if (_isMesasActive)
  381. DataColumn(
  382. label:
  383. Text("MESA", style: estilo)),
  384. DataColumn(
  385. label:
  386. Text("FOLIO", style: estilo)),
  387. DataColumn(
  388. label:
  389. Text("NOMBRE", style: estilo)),
  390. DataColumn(
  391. label: Text("COMENTARIOS",
  392. style: estilo)),
  393. DataColumn(
  394. label:
  395. Text("ESTATUS", style: estilo)),
  396. DataColumn(
  397. label:
  398. Text("FECHA", style: estilo)),
  399. DataColumn(
  400. label: Text("SINCRONIZADO",
  401. style: estilo)),
  402. ],
  403. rows: registros,
  404. ),
  405. ),
  406. ),
  407. ),
  408. );
  409. }),
  410. ],
  411. ),
  412. ),
  413. const SizedBox(height: 15),
  414. if (!pvm.isLoading)
  415. Row(
  416. mainAxisAlignment: MainAxisAlignment.center,
  417. children: [
  418. TextButton(
  419. onPressed:
  420. pvm.currentPage > 1 ? pvm.previousPage : null,
  421. child: Text('Anterior'),
  422. style: ButtonStyle(
  423. backgroundColor:
  424. MaterialStateProperty.resolveWith<Color?>(
  425. (Set<MaterialState> states) {
  426. if (states.contains(MaterialState.disabled)) {
  427. return Colors.grey;
  428. }
  429. return AppTheme.tertiary;
  430. },
  431. ),
  432. foregroundColor:
  433. MaterialStateProperty.resolveWith<Color?>(
  434. (Set<MaterialState> states) {
  435. if (states.contains(MaterialState.disabled)) {
  436. return Colors.black;
  437. }
  438. return Colors.white;
  439. },
  440. ),
  441. ),
  442. ),
  443. SizedBox(width: 15),
  444. Text(
  445. 'Página ${pvm.currentPage} de ${pvm.totalPages}'),
  446. SizedBox(width: 15),
  447. TextButton(
  448. onPressed: pvm.currentPage < pvm.totalPages
  449. ? pvm.nextPage
  450. : null,
  451. child: Text('Siguiente'),
  452. style: ButtonStyle(
  453. backgroundColor:
  454. MaterialStateProperty.resolveWith<Color?>(
  455. (Set<MaterialState> states) {
  456. if (states.contains(MaterialState.disabled)) {
  457. return Colors.grey;
  458. }
  459. return AppTheme.tertiary;
  460. },
  461. ),
  462. foregroundColor:
  463. MaterialStateProperty.resolveWith<Color?>(
  464. (Set<MaterialState> states) {
  465. if (states.contains(MaterialState.disabled)) {
  466. return Colors.black;
  467. }
  468. return Colors.white;
  469. },
  470. ),
  471. ),
  472. ),
  473. ],
  474. ),
  475. const SizedBox(height: 15),
  476. ],
  477. ),
  478. ),
  479. ],
  480. ),
  481. Positioned(
  482. bottom: 16,
  483. right: 16,
  484. child: FloatingActionButton.extended(
  485. heroTag: 'addPedido',
  486. onPressed: () async {
  487. final corteCajaViewModel =
  488. Provider.of<CorteCajaViewModel>(context, listen: false);
  489. if (corteCajaViewModel.hasOpenCorteCaja()) {
  490. await Navigator.push(
  491. context,
  492. MaterialPageRoute(
  493. builder: (context) => PedidoForm(),
  494. ),
  495. ).then((_) =>
  496. Provider.of<PedidoViewModel>(context, listen: false)
  497. .fetchLocalPedidosForScreen());
  498. } else {
  499. alerta(context,
  500. etiqueta:
  501. 'Solo se pueden realizar pedidos cuando se encuentre la caja abierta.');
  502. }
  503. },
  504. icon: Icon(Icons.add, size: 30, color: AppTheme.quaternary),
  505. label: Text(
  506. "Agregar Pedido",
  507. style: TextStyle(fontSize: 20, color: AppTheme.quaternary),
  508. ),
  509. shape: RoundedRectangleBorder(
  510. borderRadius: BorderRadius.circular(8),
  511. ),
  512. materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
  513. backgroundColor: AppTheme.tertiary,
  514. ),
  515. ),
  516. ],
  517. ),
  518. );
  519. }
  520. Widget _buildDateRangePicker() {
  521. return Row(
  522. children: [
  523. Expanded(
  524. flex: 3,
  525. child: AppTextField(
  526. prefixIcon: const Icon(Icons.search),
  527. etiqueta: 'Búsqueda por folio...',
  528. controller: _busqueda,
  529. hintText: 'Búsqueda por folio...',
  530. ),
  531. ),
  532. const SizedBox(width: 5),
  533. Expanded(
  534. flex: 3,
  535. child: clase.FechaSelectWidget(
  536. fecha: fechaInicio,
  537. onFechaChanged: (d) {
  538. setState(() {
  539. fechaInicio = d;
  540. });
  541. },
  542. etiqueta: "Fecha Inicial",
  543. context: context,
  544. ),
  545. ),
  546. const SizedBox(width: 5),
  547. Expanded(
  548. flex: 3,
  549. child: clase.FechaSelectWidget(
  550. fecha: fechaFin,
  551. onFechaChanged: (d) {
  552. setState(() {
  553. fechaFin = d;
  554. });
  555. },
  556. etiqueta: "Fecha Final",
  557. context: context,
  558. ),
  559. ),
  560. ],
  561. );
  562. }
  563. Widget botonBuscar() {
  564. return Expanded(
  565. flex: 2,
  566. child: Row(
  567. children: [
  568. Expanded(
  569. flex: 2,
  570. child: Padding(
  571. padding: const EdgeInsets.only(bottom: 5),
  572. child: ElevatedButton(
  573. onPressed: clearSearchAndReset,
  574. style: ElevatedButton.styleFrom(
  575. shape: RoundedRectangleBorder(
  576. borderRadius: BorderRadius.circular(20.0),
  577. ),
  578. primary: AppTheme.tertiary,
  579. padding: const EdgeInsets.symmetric(vertical: 25),
  580. ),
  581. child: Text('Limpiar',
  582. style: TextStyle(color: AppTheme.quaternary)),
  583. ),
  584. ),
  585. ),
  586. const SizedBox(width: 8),
  587. Expanded(
  588. flex: 2,
  589. child: Padding(
  590. padding: const EdgeInsets.only(bottom: 5),
  591. child: ElevatedButton(
  592. onPressed: () async {
  593. if (_busqueda.text.isNotEmpty) {
  594. await Provider.of<PedidoViewModel>(context, listen: false)
  595. .buscarPedidosPorFolio(_busqueda.text.trim());
  596. } else if (fechaInicio != null && fechaFin != null) {
  597. DateTime fechaInicioUTC = DateTime(fechaInicio!.year,
  598. fechaInicio!.month, fechaInicio!.day)
  599. .toUtc();
  600. DateTime fechaFinUTC = DateTime(fechaFin!.year,
  601. fechaFin!.month, fechaFin!.day, 23, 59, 59)
  602. .toUtc();
  603. await Provider.of<PedidoViewModel>(context, listen: false)
  604. .buscarPedidosPorFecha(fechaInicioUTC, fechaFinUTC);
  605. } else {
  606. ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
  607. content: Text(
  608. 'Introduce un folio o selecciona un rango de fechas para buscar.')));
  609. }
  610. },
  611. style: ElevatedButton.styleFrom(
  612. shape: RoundedRectangleBorder(
  613. borderRadius: BorderRadius.circular(20.0),
  614. ),
  615. primary: AppTheme.tertiary,
  616. padding: const EdgeInsets.symmetric(vertical: 25),
  617. ),
  618. child: Text('Buscar',
  619. style: TextStyle(color: AppTheme.quaternary)),
  620. ),
  621. ),
  622. ),
  623. ],
  624. ),
  625. );
  626. }
  627. void alertaSync(BuildContext context) {
  628. showDialog(
  629. context: context,
  630. builder: (BuildContext context) {
  631. return AlertDialog(
  632. title: const Text('Confirmación',
  633. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22)),
  634. content: const Text('¿Deseas sincronizar todos los pedidos de nuevo?',
  635. style: TextStyle(fontSize: 18)),
  636. actions: [
  637. Row(
  638. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  639. children: [
  640. TextButton(
  641. child: const Text('No', style: TextStyle(fontSize: 18)),
  642. style: ButtonStyle(
  643. padding: MaterialStatePropertyAll(
  644. EdgeInsets.fromLTRB(20, 10, 20, 10)),
  645. backgroundColor: MaterialStatePropertyAll(Colors.red),
  646. foregroundColor:
  647. MaterialStatePropertyAll(AppTheme.secondary)),
  648. onPressed: () {
  649. Navigator.of(context).pop();
  650. },
  651. ),
  652. TextButton(
  653. child: const Text('Sí', style: TextStyle(fontSize: 18)),
  654. style: ButtonStyle(
  655. padding: MaterialStatePropertyAll(
  656. EdgeInsets.fromLTRB(20, 10, 20, 10)),
  657. backgroundColor:
  658. MaterialStatePropertyAll(AppTheme.tertiary),
  659. foregroundColor:
  660. MaterialStatePropertyAll(AppTheme.quaternary)),
  661. onPressed: () {
  662. // No hace nada por el momento
  663. Navigator.of(context).pop();
  664. },
  665. ),
  666. ],
  667. )
  668. ],
  669. );
  670. },
  671. );
  672. }
  673. String _formatDateTime(String? dateTimeString) {
  674. if (dateTimeString == null) return "Sin fecha";
  675. DateTime parsedDate = DateTime.parse(dateTimeString);
  676. var formatter = DateFormat('dd-MM-yyyy HH:mm:ss');
  677. return formatter.format(parsedDate.toLocal());
  678. }
  679. }