widgets_components.dart 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. // ignore_for_file: use_build_context_synchronously, prefer_if_null_operators, prefer_conditional_assignment
  2. import 'dart:io';
  3. import 'dart:typed_data';
  4. import 'package:camera/camera.dart';
  5. import 'package:flutter/material.dart';
  6. //import 'package:yoshi_papas_app/viewmodels/media_view_model.dart';
  7. import 'package:intl/intl.dart';
  8. import 'package:omni_datetime_picker/omni_datetime_picker.dart';
  9. import 'package:flutter/material.dart' as d;
  10. import 'package:datetime_picker_formfield/datetime_picker_formfield.dart' as d2;
  11. import 'package:provider/provider.dart';
  12. import 'package:url_launcher/url_launcher.dart';
  13. import 'package:flutter/foundation.dart' show kIsWeb;
  14. import 'package:path_provider/path_provider.dart';
  15. //import '../data/session/session_storage.dart';
  16. import '../models/media_model.dart';
  17. import '../themes/themes.dart';
  18. import 'package:timezone/timezone.dart' as tz;
  19. import 'package:http/http.dart' as http;
  20. import "package:universal_html/html.dart" as html;
  21. //import '../viewmodels/ordenes_view_model.dart';
  22. //import 'dart:html';
  23. //import 'dart:html' as html;
  24. encabezado(
  25. {double elevacion = 1,
  26. List<Widget>? acciones,
  27. PreferredSize? bottom,
  28. Color? backgroundColor,
  29. String? nombre,
  30. Widget? leading = null,
  31. String? titulo,
  32. bool centerTitle = true}) {
  33. TextStyle estilo = const TextStyle(fontWeight: FontWeight.bold);
  34. if (acciones == null) {
  35. acciones = [];
  36. }
  37. return AppBar(
  38. leading: leading,
  39. elevation: elevacion,
  40. backgroundColor: backgroundColor,
  41. centerTitle: centerTitle,
  42. title: titulo == null
  43. ? Image.asset("assets/OlivaLogo.png", width: 100)
  44. : Text(titulo.toString(), style: estilo),
  45. actions: [
  46. ...acciones,
  47. Image.asset("assets/OlivaLogo.png", width: 100),
  48. ],
  49. bottom: bottom);
  50. }
  51. tarjeta(Widget item, {Color color = Colors.white, double padding = 0}) {
  52. if (padding > 0) {
  53. return Padding(
  54. padding: const EdgeInsets.all(0),
  55. child: Card(
  56. color: color,
  57. shape:
  58. RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  59. margin: const EdgeInsets.only(bottom: 16),
  60. elevation: 0,
  61. borderOnForeground: true,
  62. child: Padding(padding: EdgeInsets.all(padding), child: item)));
  63. }
  64. return Card(
  65. color: color,
  66. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  67. margin: const EdgeInsets.only(bottom: 8),
  68. elevation: 0,
  69. borderOnForeground: true,
  70. child: Padding(
  71. padding: const EdgeInsets.all(8),
  72. child: item,
  73. ));
  74. }
  75. class Cargando extends StatelessWidget {
  76. const Cargando({super.key});
  77. @override
  78. Widget build(BuildContext context) {
  79. return Scaffold(
  80. backgroundColor: const Color(0xFFE0E0E0),
  81. body: Center(
  82. child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
  83. Padding(
  84. padding: const EdgeInsets.fromLTRB(16, 0, 16, 10),
  85. child: Image.asset("assets/OlivaLogo.png", height: 200)),
  86. const CircularProgressIndicator(backgroundColor: Colors.grey),
  87. Container(margin: const EdgeInsets.only(bottom: 8.0)),
  88. const Text("Cargando contenido...",
  89. style: TextStyle(
  90. fontWeight: FontWeight.bold,
  91. fontSize: 16,
  92. color: Colors.black)),
  93. const Text("Por favor espere.",
  94. style: TextStyle(
  95. fontWeight: FontWeight.bold,
  96. fontSize: 16,
  97. color: Colors.black),
  98. textAlign: TextAlign.center)
  99. ]),
  100. ));
  101. }
  102. }
  103. boton(String etiqueta, Function()? accion,
  104. {double height = 75, double width = 380}) {
  105. return Align(
  106. alignment: Alignment.topLeft,
  107. child: SizedBox(
  108. height: height,
  109. width: 380,
  110. child: ElevatedButton(
  111. style: ButtonStyle(
  112. shape: MaterialStatePropertyAll(
  113. RoundedRectangleBorder(
  114. borderRadius: BorderRadius.circular(10),
  115. ),
  116. ),
  117. backgroundColor: MaterialStatePropertyAll(AppTheme.tertiary),
  118. ),
  119. onPressed: accion,
  120. child: Row(
  121. mainAxisAlignment: MainAxisAlignment.center,
  122. children: [
  123. Text(etiqueta,
  124. style: TextStyle(fontSize: 18, color: AppTheme.quaternary)),
  125. ],
  126. ),
  127. ),
  128. ),
  129. );
  130. }
  131. Future<DateTime?> showHora(BuildContext context, DateTime? fecha) async {
  132. if (fecha == null) {
  133. return fecha;
  134. }
  135. final tiempo = await showTimePicker(
  136. useRootNavigator: false,
  137. helpText: "CAPTURAR HORA",
  138. confirmText: "ACEPTAR",
  139. cancelText: "CANCELAR",
  140. hourLabelText: "HORA",
  141. minuteLabelText: "MINUTO",
  142. initialEntryMode: TimePickerEntryMode.input,
  143. context: context,
  144. initialTime: TimeOfDay.fromDateTime(fecha),
  145. builder: (context, childs) {
  146. return MediaQuery(
  147. data: MediaQuery.of(context).copyWith(
  148. alwaysUse24HourFormat: true,
  149. padding: const EdgeInsets.all(1),
  150. size: const Size.square(1),
  151. textScaler: const TextScaler.linear(.8)),
  152. child: childs!);
  153. },
  154. );
  155. return d2.DateTimeField.combine(fecha!, tiempo);
  156. }
  157. Future<DateTime?> showDatetimePicker(BuildContext context, DateTime? fecha,
  158. {DateTime? inicia,
  159. DateTime? termina,
  160. OmniDateTimePickerType tipo = OmniDateTimePickerType.dateAndTime,
  161. bool solofecha = false}) async {
  162. if (termina == null) {
  163. termina = DateTime(2030);
  164. }
  165. final f = await showDatePicker(
  166. context: context,
  167. initialDate: fecha ?? DateTime.now(),
  168. firstDate: inicia ?? DateTime(2023),
  169. lastDate: termina,
  170. cancelText: "CANCELAR",
  171. confirmText: "ACEPTAR",
  172. builder: (context, child) {
  173. return Theme(
  174. data: Theme.of(context).copyWith(
  175. colorScheme: ColorScheme.light(
  176. primary: AppTheme.primary,
  177. onSurface: AppTheme.secondary,
  178. ),
  179. textButtonTheme: TextButtonThemeData(
  180. style: TextButton.styleFrom(
  181. primary: AppTheme.secondary,
  182. ),
  183. ),
  184. ),
  185. child: child!,
  186. );
  187. },
  188. );
  189. if (f == null || solofecha) {
  190. return f;
  191. }
  192. final tiempo = await showTimePicker(
  193. context: context,
  194. initialTime: TimeOfDay.fromDateTime(f),
  195. helpText: "CAPTURAR HORA",
  196. confirmText: "ACEPTAR",
  197. cancelText: "CANCELAR",
  198. hourLabelText: "HORA",
  199. minuteLabelText: "MINUTO",
  200. initialEntryMode: TimePickerEntryMode.input,
  201. builder: (context, child) {
  202. return Theme(
  203. data: Theme.of(context).copyWith(
  204. colorScheme: ColorScheme.light(
  205. primary: AppTheme.primary,
  206. onSurface: AppTheme.secondary,
  207. ),
  208. textButtonTheme: TextButtonThemeData(
  209. style: TextButton.styleFrom(
  210. primary: AppTheme.secondary,
  211. ),
  212. ),
  213. ),
  214. child: child!,
  215. );
  216. },
  217. );
  218. return d2.DateTimeField.combine(f, tiempo);
  219. }
  220. class FechaSelectWidget extends StatelessWidget {
  221. final DateTime? fecha;
  222. final Function(DateTime) onFechaChanged;
  223. final String etiqueta;
  224. final BuildContext context;
  225. const FechaSelectWidget({
  226. Key? key,
  227. required this.fecha,
  228. required this.onFechaChanged,
  229. required this.etiqueta,
  230. required this.context,
  231. }) : super(key: key);
  232. @override
  233. Widget build(BuildContext context) {
  234. return Column(
  235. crossAxisAlignment: CrossAxisAlignment.start,
  236. children: [
  237. Text(
  238. etiqueta,
  239. style: const TextStyle(
  240. fontWeight: FontWeight.bold,
  241. fontSize: 16,
  242. ),
  243. ),
  244. const SizedBox(height: 5),
  245. InkWell(
  246. onTap: () async {
  247. DateTime? d = await showDatetimePicker(
  248. context,
  249. fecha,
  250. tipo: OmniDateTimePickerType.date,
  251. solofecha: true,
  252. );
  253. if (d == null) return;
  254. onFechaChanged(d);
  255. },
  256. child: Container(
  257. decoration: BoxDecoration(
  258. border: Border.all(color: Colors.grey[400]!),
  259. borderRadius: BorderRadius.circular(10),
  260. ),
  261. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
  262. child: Row(
  263. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  264. children: [
  265. Text(
  266. fecha == null
  267. ? "Seleccionar"
  268. : DateFormat("dd/MM/yyyy").format(fecha!),
  269. style: TextStyle(
  270. color: fecha == null ? Colors.grey : Colors.black,
  271. ),
  272. ),
  273. const Icon(Icons.calendar_month),
  274. ],
  275. ),
  276. ),
  277. ),
  278. ],
  279. );
  280. }
  281. }
  282. Widget circulo(Widget item, {Function()? accion, Color? color}) {
  283. color ??= Colors.black;
  284. return InkWell(
  285. onTap: accion,
  286. child: Container(
  287. decoration: BoxDecoration(
  288. border: Border.all(
  289. color: color, // <--- border color
  290. width: 2.0,
  291. ),
  292. borderRadius: const BorderRadius.all(
  293. Radius.circular(50) // <--- border radius here
  294. ),
  295. ),
  296. child: item));
  297. }
  298. alerta(BuildContext context, {String? etiqueta = "Capturar búsqueda"}) {
  299. return showDialog(
  300. context: context,
  301. builder: (context) {
  302. return AlertDialog(
  303. title: Text(etiqueta.toString()),
  304. actions: [
  305. Row(children: [
  306. Expanded(
  307. child: TextButton(
  308. onPressed: () async {
  309. Navigator.pop(context);
  310. },
  311. child: const Text('Continuar'),
  312. ))
  313. ])
  314. ],
  315. );
  316. });
  317. }
  318. botonElevated(
  319. {Function()? accion,
  320. String? titulo = "Buscar",
  321. Color color = Colors.black}) {
  322. return ElevatedButton(
  323. style: ElevatedButton.styleFrom(
  324. backgroundColor: color,
  325. shape: RoundedRectangleBorder(
  326. borderRadius: BorderRadius.circular(12), // <-- Radius
  327. )),
  328. onPressed: accion,
  329. child: Text(
  330. titulo.toString(),
  331. style: const TextStyle(color: Colors.white),
  332. ),
  333. );
  334. }
  335. Widget xMedia(XFile m) {
  336. bool archivo = false;
  337. Widget icono = const Icon(Icons.file_copy, size: 50);
  338. int lastIndex = m.name.lastIndexOf('.');
  339. String extension = "";
  340. if (lastIndex != -1 && lastIndex < m.name.length - 1) {
  341. extension = m.name.substring(lastIndex + 1);
  342. }
  343. switch (extension) {
  344. case "mp4":
  345. archivo = true;
  346. icono = const Icon(Icons.video_file, size: 50);
  347. break;
  348. case "wav":
  349. archivo = true;
  350. icono = Image.asset("assets/audio-file.png");
  351. archivo = true;
  352. break;
  353. case "jpeg":
  354. case "jpg":
  355. case "png":
  356. break;
  357. case "pdf":
  358. icono = Image.asset("assets/pdf-file.png");
  359. archivo = true;
  360. break;
  361. case "csv":
  362. case "docx":
  363. icono = Image.asset("assets/word.png");
  364. archivo = true;
  365. break;
  366. case "xlsx":
  367. icono = Image.asset("assets/excel.png");
  368. archivo = true;
  369. break;
  370. }
  371. String nombre = m.name.toString();
  372. if (nombre.length > 25) {
  373. nombre = "${m.name.toString().substring(0, 24)}...";
  374. }
  375. return InkWell(
  376. onTap: () async {
  377. String url = m.path.toString();
  378. await canLaunch(url)
  379. ? await launch(url, forceSafariVC: false, forceWebView: false)
  380. : print('Could not launch '); //aqui
  381. },
  382. child: Stack(alignment: Alignment.center, children: [
  383. Container(
  384. height: 100.0,
  385. width: 100.0,
  386. clipBehavior: Clip.antiAlias,
  387. decoration: BoxDecoration(
  388. border: Border.all(color: Colors.black, width: 1.0),
  389. borderRadius: const BorderRadius.all(Radius.circular(15.0)),
  390. ),
  391. child: archivo
  392. ? icono
  393. : Image.network(m.path.toString(),
  394. scale:
  395. 1) // _firma == null?const Icon(Icons.pages, size: 30, color: Colors.black): contenedorFirma,
  396. ),
  397. Positioned(
  398. bottom: 0,
  399. child: Container(
  400. width: 200,
  401. height: 40,
  402. color: Colors.grey.shade800,
  403. child: Column(
  404. mainAxisAlignment: MainAxisAlignment.center,
  405. children: [
  406. Text(
  407. nombre,
  408. textAlign: TextAlign.center,
  409. textScaler: const TextScaler.linear(.8),
  410. style: const TextStyle(color: Colors.white),
  411. ),
  412. ]),
  413. )),
  414. ]));
  415. }
  416. Widget wMedia(Media m, {Function()? eliminar}) {
  417. bool archivo = false;
  418. Widget icono = const Icon(Icons.file_copy, size: 50);
  419. switch (m.extension) {
  420. case "mp4":
  421. archivo = true;
  422. icono = const Icon(Icons.video_file, size: 50);
  423. break;
  424. case "wav":
  425. archivo = true;
  426. icono = Image.asset("assets/audio-file.png");
  427. archivo = true;
  428. break;
  429. case "jpeg":
  430. case "jpg":
  431. case "png":
  432. break;
  433. case "pdf":
  434. icono = Image.asset("assets/pdf-file.png");
  435. archivo = true;
  436. break;
  437. case "csv":
  438. case "docx":
  439. icono = Image.asset("assets/word.png");
  440. archivo = true;
  441. break;
  442. case "xlsx":
  443. icono = Image.asset("assets/excel.png");
  444. archivo = true;
  445. break;
  446. }
  447. String fecha = "";
  448. if (m.creado != null) {
  449. String timeZone = 'America/Hermosillo';
  450. fecha = formatFechaConZonaHoraria(m.creado!, timeZone);
  451. }
  452. String nombre = m.nombre.toString();
  453. if (nombre.length > 25) {
  454. nombre = "${m.nombre.toString().substring(0, 24)}...";
  455. }
  456. return InkWell(
  457. onTap: () async {
  458. String url = m.ruta.toString();
  459. await canLaunch(url)
  460. ? await launch(url, forceSafariVC: false, forceWebView: false)
  461. : print('Could not launch '); //aqui
  462. },
  463. child: Stack(alignment: Alignment.center, children: [
  464. Container(
  465. height: 160.0,
  466. width: 160.0,
  467. clipBehavior: Clip.antiAlias,
  468. decoration: BoxDecoration(
  469. border: Border.all(color: Colors.black, width: 1.0),
  470. borderRadius: const BorderRadius.all(Radius.circular(15.0)),
  471. ),
  472. child: archivo
  473. ? icono
  474. : Image.network(m.ruta.toString(),
  475. scale:
  476. 1) // _firma == null?const Icon(Icons.pages, size: 30, color: Colors.black): contenedorFirma,
  477. ),
  478. Positioned(
  479. bottom: 0,
  480. child: Container(
  481. width: 500,
  482. height: 40,
  483. color: Colors.grey.shade800,
  484. child: Column(
  485. mainAxisAlignment: MainAxisAlignment.center,
  486. children: [
  487. Text(
  488. nombre,
  489. textAlign: TextAlign.center,
  490. textScaler: const TextScaler.linear(.8),
  491. style: const TextStyle(color: Colors.white),
  492. ),
  493. Text(
  494. fecha,
  495. textAlign: TextAlign.center,
  496. textScaler: const TextScaler.linear(.8),
  497. style: const TextStyle(color: Colors.white),
  498. ),
  499. ]),
  500. )),
  501. Positioned(
  502. left: 0,
  503. top: 0,
  504. child: ElevatedButton(
  505. onPressed: eliminar,
  506. style: ElevatedButton.styleFrom(
  507. shape: CircleBorder(),
  508. padding: EdgeInsets.all(16),
  509. ),
  510. child: Icon(
  511. Icons.delete,
  512. color: Colors.red.shade800,
  513. ),
  514. ),
  515. ),
  516. ]));
  517. }
  518. Widget agregarMedia(
  519. {Color color = Colors.green,
  520. Function()? accion,
  521. String titulo = "Agregar Media",
  522. Icon? icono,
  523. double tamano = 160}) {
  524. if (icono == null) {
  525. icono = Icon(
  526. Icons.add,
  527. size: tamano < 100 ? 60 : 100,
  528. color: Colors.white,
  529. );
  530. }
  531. return InkWell(
  532. onTap: accion,
  533. child: Stack(alignment: Alignment.center, children: [
  534. // Contenedor con un color de fondo y dimensiones específicas
  535. Container(
  536. width: tamano,
  537. height: tamano,
  538. color: color,
  539. ),
  540. // Texto flotante
  541. Positioned(
  542. child:
  543. Column(mainAxisAlignment: MainAxisAlignment.center, children: [
  544. icono,
  545. titulo.isEmpty
  546. ? Container()
  547. : Text(
  548. titulo,
  549. style: const TextStyle(
  550. color: Colors.white,
  551. fontSize: 16,
  552. ),
  553. ),
  554. ])),
  555. ]));
  556. }
  557. String formatFechaConZonaHoraria(DateTime dateTime, String timeZone) {
  558. // Obtiene la ubicación de la zona horaria
  559. tz.Location location = tz.getLocation(timeZone);
  560. // Convierte la fecha a la zona horaria deseada
  561. tz.TZDateTime fechaConZona = tz.TZDateTime.from(dateTime, location);
  562. // Formatea la fecha con la zona horaria
  563. //String formattedFecha = DateFormat("dd/MM/yyyy HH:mm '($timeZone)'").format(fechaConZona);
  564. String formattedFecha = DateFormat("dd/MM/yyyy HH:mm").format(fechaConZona);
  565. return formattedFecha;
  566. }
  567. html.Location getLocation(String timeZone) {
  568. // Obtiene la ubicación de la zona horaria
  569. return getLocation(timeZone);
  570. }
  571. int obtenerAxiscount(Size s) {
  572. int axiscount = 8;
  573. if (s.width > 1300) {
  574. axiscount = 8;
  575. }
  576. if (s.width > 900 && s.width < 1300) {
  577. axiscount = 5;
  578. }
  579. if (s.width > 700 && s.width < 900) {
  580. axiscount = 4;
  581. }
  582. if (s.width > 600 && s.width < 700) {
  583. axiscount = 3;
  584. }
  585. if (s.width < 600) {
  586. axiscount = 2;
  587. }
  588. return axiscount;
  589. }
  590. // imprimirExcel(String url, String nombre) async {
  591. // var t = await SessionStorage().getToken();
  592. // Map<String, String> headers = {
  593. // 'Authorization': 'Bearer $t',
  594. // 'Content-Type': 'application/json', // Puedes ajustar según sea necesario
  595. // };
  596. // http.Response response = await http.get(
  597. // Uri.parse(url),
  598. // headers: headers,
  599. // );
  600. // if (response.statusCode == 200) {
  601. // // Obtener el contenido del archivo como Uint8List
  602. // Uint8List fileBytes = response.bodyBytes;
  603. // if (!kIsWeb) {
  604. // // Lógica para dispositivos móviles y escritorio
  605. // final directory = await getApplicationDocumentsDirectory();
  606. // final path = '${directory.path}/$nombre.xlsx';
  607. // final file = File(path);
  608. // await file.writeAsBytes(fileBytes);
  609. // final Uri fileUri = Uri.file(path);
  610. // if (await canLaunchUrl(fileUri)) {
  611. // await launchUrl(fileUri);
  612. // } else {
  613. // throw 'No se pudo abrir el archivo';
  614. // }
  615. // return; // Retorna después de manejar la lógica de dispositivos móviles
  616. // }
  617. // // Lógica específica para la web sigue aquí
  618. // // Asegúrate de que este código solo se ejecute en la web
  619. // if (kIsWeb) {
  620. // // Crea y descarga el archivo para la web
  621. // final blob = html.Blob([fileBytes]);
  622. // final url = html.Url.createObjectUrlFromBlob(blob);
  623. // final anchor = html.AnchorElement(href: url)
  624. // ..setAttribute('download', '$nombre.xlsx')
  625. // ..click();
  626. // html.Url.revokeObjectUrl(url);
  627. // }
  628. // } else {
  629. // print(
  630. // 'Error al descargar el archivo. Código de estado: ${response.statusCode}');
  631. // }
  632. // }
  633. // imprimirPdf(String url, String nombre) async {
  634. // var t = await SessionStorage().getToken();
  635. // Map<String, String> headers = {
  636. // 'Authorization': 'Bearer $t',
  637. // 'Content-Type': 'application/json', // Puedes ajustar según sea necesario
  638. // };
  639. // http.Response response = await http.get(
  640. // Uri.parse(url),
  641. // headers: headers,
  642. // );
  643. // if (response.statusCode == 200) {
  644. // // Obtener el contenido del archivo como Uint8List
  645. // Uint8List fileBytes = response.bodyBytes;
  646. // // Crear un blob con los bytes del archivo
  647. // final blob = html.Blob([fileBytes]);
  648. // // Crear un objeto URL para el blob
  649. // final url = html.Url.createObjectUrlFromBlob(blob);
  650. // // Crear un enlace de descarga y hacer clic en él para descargar el archivo
  651. // final anchor = html.AnchorElement(href: url)
  652. // ..target = 'blank'
  653. // ..download =
  654. // '$nombre.pdf'; // Ajustar el nombre y la extensión del archivo
  655. // anchor.click();
  656. // // Liberar el objeto URL
  657. // html.Url.revokeObjectUrl(url);
  658. // } else {
  659. // print(
  660. // 'Error al descargar el archivo. Código de estado: ${response.statusCode}');
  661. // }
  662. // }
  663. Widget usuarioHeader(String nombre, String correo) {
  664. return Row(
  665. mainAxisAlignment: MainAxisAlignment.center,
  666. crossAxisAlignment: CrossAxisAlignment.center,
  667. children: [
  668. Column(
  669. mainAxisAlignment: MainAxisAlignment.center,
  670. crossAxisAlignment: CrossAxisAlignment.end,
  671. children: [
  672. Text(nombre,
  673. style: TextStyle(
  674. color: Colors.black, fontWeight: FontWeight.bold),
  675. textAlign: TextAlign.right),
  676. Text(correo,
  677. style: TextStyle(color: Colors.grey.shade900),
  678. textAlign: TextAlign.right),
  679. ]),
  680. Text(" "),
  681. CircleAvatar(
  682. child: Icon(Icons.verified_user, color: Colors.white),
  683. backgroundColor: Colors.black),
  684. Text(" "),
  685. ]);
  686. }
  687. Future eliminarMedia(
  688. BuildContext context, Media m, Function()? confirmacion) async {
  689. return await showDialog(
  690. context: context,
  691. builder: (context) {
  692. return AlertDialog(
  693. surfaceTintColor: AppTheme.secondary,
  694. title: const Text('¿Desea eliminar esta archivo?'),
  695. actions: [
  696. TextButton(
  697. onPressed: () {
  698. Navigator.pop(context);
  699. },
  700. child: const Text('Cancelar'),
  701. ),
  702. TextButton(
  703. onPressed: confirmacion,
  704. child: const Text(
  705. 'Sí, estoy seguro',
  706. style: TextStyle(color: Colors.red),
  707. ),
  708. ),
  709. ],
  710. );
  711. },
  712. );
  713. }