import 'package:computo_lite/main.dart'; import 'package:computo_lite/views/package/package_store.dart'; import 'package:computo_lite/viewmodels/viewmodels.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; const Map showButtonsConsejos = { 1: [1], 2: [1, 2, 3], 3: [1, 3] }; class PackagePage extends StatefulWidget { final Map _package; final List> _binnacle; final String _entradaSalida; final bool _scanner; final int _idConsejoElectoralBitacora; final int _idTipoEleccion; PackagePage(this._package, this._binnacle, this._entradaSalida, this._scanner, this._idConsejoElectoralBitacora, this._idTipoEleccion) : super(); @override _PackagePageState createState() => _PackagePageState(); } class _PackagePageState extends State { final StoreViewModel _storeViewModel = StoreViewModel(); String numeros = ""; // Inicializar como vacío String nombre = ""; // Inicializar como vacío String primeraLetraNombre = ""; bool _verifying = false; @override void initState() { super.initState(); _initializePackageData(); // Llamar a este método en initState } void _initializePackageData() { String textoCompleto = widget._package["nombreCompletoActa"].toString(); int indiceEspacio = textoCompleto.indexOf(' '); if (indiceEspacio != -1) { // Asegurarse de que se encontró un espacio numeros = textoCompleto.substring(0, indiceEspacio); nombre = textoCompleto.substring(indiceEspacio + 1); if (nombre.isNotEmpty) { primeraLetraNombre = nombre[0]; // Extraer la primera letra del nombre } } } Future _verifySotre(String sacarAlmacenar) async { try { if (mounted) setState(() => _verifying = true); final bool openStore = await _storeViewModel.openStore(); if (!openStore) { HelpersViewModel.dialog( 2, const Row( children: [ Icon(Icons.error), SizedBox(width: 5), Text("Error"), ], ), "La bodega esta cerrada.", context, "Cerrar", "Ir a bodega", () {}, () { //Navigator.push(context, MaterialPageRoute(builder: (context) => MyApp(pageSelected: 3))); }); return; } // Navigator.push( // context, // MaterialPageRoute( // builder: (context) => // PackageStore(sacarAlmacenar, widget._package, widget._scanner)), // ); } catch (e) { print(e); } finally { if (mounted) setState(() => _verifying = false); } } @override Widget build(BuildContext context) { // final Map user = // Provider.of(context, listen: true).userData; return Scaffold( // floatingActionButton: _verifying // ? const CircularProgressIndicator() // : widget._entradaSalida == "E" // ? widget._idTipoEleccion == // user["consejoElectoral"]["idTipoConsejoElectoral"] && // widget._idConsejoElectoralBitacora == // user["consejoElectoral"]["idConsejoElectoral"] // ? Padding( // padding: const EdgeInsets.only(left: 30.0), // child: SizedBox( // width: double.infinity, // child: TextButton( // onPressed: () async => await _verifySotre("S"), // style: ButtonStyle( // backgroundColor: // MaterialStateProperty.all( // const Color(0xffdb6500))), // child: const Text( // "Sacar", // style: TextStyle(color: Colors.white), // )), // ), // ) // : widget._idConsejoElectoralBitacora != // user["consejoElectoral"]["idConsejoElectoral"] // ? Padding( // padding: const EdgeInsets.only(left: 30.0), // child: SizedBox( // width: double.infinity, // child: TextButton( // onPressed: () async => await _verifySotre("E"), // style: ButtonStyle( // backgroundColor: // MaterialStateProperty.all( // const Color(0xffdb6500))), // child: const Text( // "Almacenar", // style: TextStyle(color: Colors.white), // )), // ), // ) // : const SizedBox() // : List.from(showButtonsConsejos[user["consejoElectoral"] // ["idTipoConsejoElectoral"]]) // .contains(widget._package["idTipoEleccion"]) // ? Padding( // padding: const EdgeInsets.only(left: 30.0), // child: SizedBox( // width: double.infinity, // child: TextButton( // onPressed: () async => await _verifySotre("E"), // style: ButtonStyle( // backgroundColor: // MaterialStateProperty.all( // const Color(0xffdb6500))), // child: const Text( // "Almacenar", // style: TextStyle(color: Colors.white), // )), // ), // ) // : const SizedBox(), appBar: AppBar( centerTitle: true, iconTheme: const IconThemeData(color: Colors.white), title: Image.asset("assets/logo_iee.png", height: 50), ), body: _packageInfo(), ); } Widget _packageInfo() { return Padding( padding: const EdgeInsets.all(20.0), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox(height: 10), const Center( child: Text("Acta / Paquete", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold))), const SizedBox(height: 20), Row(children: [ const Icon( Icons.description_outlined, size: 150, ), RichText( text: TextSpan( children: [ const TextSpan( text: /*"$primeraLetraNombre\n"*/ "C\n", // Aquí se usa la variable primeraLetraNombre style: TextStyle( fontWeight: FontWeight.bold, color: Color(0xFF0000FF), fontSize: 50), ), TextSpan( text: "$numeros\n", // Agrega un salto de línea después de los números style: const TextStyle( fontWeight: FontWeight.bold, // Estilo para los números color: Color(0xFF980000), fontSize: 30 // Por ejemplo, números en azul ), ), TextSpan( text: nombre, // El nombre en la siguiente línea style: const TextStyle( fontWeight: FontWeight.normal, // Estilo para el nombre color: Colors.black, fontSize: 30 // Por ejemplo, nombre en negro ), ), ], ), ), ]), const SizedBox(height: 20), RichText( text: TextSpan( text: 'Elección: ', style: const TextStyle( fontWeight: FontWeight.bold, color: Colors.black, fontSize: 16), children: [ TextSpan( text: widget._package["tipoEleccion"]["nombre"].toString(), style: const TextStyle(fontWeight: FontWeight.normal)), ], ), ), const SizedBox(height: 20), RichText( text: TextSpan( text: 'Ubicación: ', style: const TextStyle( fontWeight: FontWeight.bold, color: Colors.black, fontSize: 16), children: [ TextSpan( text: widget._package["casilla"]["ubicacion"].toString(), style: const TextStyle(fontWeight: FontWeight.normal)), ], ), ), const SizedBox(height: 10), const Divider(indent: 2, color: Colors.black), const SizedBox(height: 10), const Center( child: Text("Recibo Capturado", style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold))), const SizedBox(height: 20), widget._package["ultimaRecepcion"]["fecha"] != null ? const Padding( padding: EdgeInsets.all(8.0), child: Center( child: Row( children: [ Icon(Icons.description_outlined, size: 80), Text("Recibo de Captura") ], ))) : const Padding( padding: EdgeInsets.all(8.0), child: Center( child: Row( children: [ Icon(Icons.watch_later_outlined, size: 80), Text("Sin Recibo") ], ))) ], ), ), ); } }