|
@@ -1,138 +1,78 @@
|
|
-import 'package:computo_lite/views/package/package_page.dart';
|
|
|
|
|
|
+import 'package:computo_lite/viewmodels/home_view_model.dart';
|
|
|
|
+import 'package:computo_lite/viewmodels/login_view_model.dart';
|
|
|
|
+import 'package:computo_lite/widgets/widgets_components.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
-import 'package:computo_lite/widgets/widgets.dart';
|
|
|
|
|
|
+import '../../widgets/app_drawer.dart';
|
|
|
|
+import '../../themes/themes.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
-import '../../viewmodels/viewmodels.dart';
|
|
|
|
-
|
|
|
|
-class HomeScreen extends StatefulWidget {
|
|
|
|
- const HomeScreen({super.key});
|
|
|
|
-
|
|
|
|
- @override
|
|
|
|
- Formulario createState() => Formulario();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class Formulario extends State<HomeScreen> {
|
|
|
|
- @override
|
|
|
|
- void initState() {
|
|
|
|
- super.initState();
|
|
|
|
- Future(() async {
|
|
|
|
- await Provider.of<LoginViewModel>(context, listen: false).setValores();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final PackageViewModel _packageViewModel = PackageViewModel();
|
|
|
|
- bool _loading = false;
|
|
|
|
-
|
|
|
|
- Future<void> _scanner() async {
|
|
|
|
- try {
|
|
|
|
- if (_loading) return;
|
|
|
|
-
|
|
|
|
- if (mounted) setState(() => _loading = true);
|
|
|
|
-
|
|
|
|
- Widget header = Row(
|
|
|
|
- children: [
|
|
|
|
- Icon(Icons.error),
|
|
|
|
- SizedBox(width: 5),
|
|
|
|
- Text("Aviso"),
|
|
|
|
- ],
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- Map<String, dynamic>? response = await _packageViewModel.scanner("");
|
|
|
|
-
|
|
|
|
- if (response == null ||
|
|
|
|
- response["resultado"] == null ||
|
|
|
|
- List.from(response["resultado"]).length == 0) {
|
|
|
|
- if (mounted) setState(() => _loading = false);
|
|
|
|
-
|
|
|
|
- await HelpersViewModel.dialog(
|
|
|
|
- 2,
|
|
|
|
- header,
|
|
|
|
- "No se encontro el Acta-Paquete, intenelo de nuevo.",
|
|
|
|
- context,
|
|
|
|
- "Cerrar",
|
|
|
|
- "Reintentar",
|
|
|
|
- () {}, () async {
|
|
|
|
- await _scanner();
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Map<String, dynamic>? binnacle = await _packageViewModel
|
|
|
|
- .getBinnacle(response["resultado"][0]["idActa"]);
|
|
|
|
-
|
|
|
|
- Navigator.push(
|
|
|
|
- context,
|
|
|
|
- MaterialPageRoute(
|
|
|
|
- builder: (context) => PackagePage(
|
|
|
|
- response["resultado"][0],
|
|
|
|
- binnacle != null
|
|
|
|
- ? List<Map<String, dynamic>>.from(binnacle["resultado"])
|
|
|
|
- .map((e) => ({
|
|
|
|
- "entradaSalida": e["entradaSalida"],
|
|
|
|
- "fecha": e["fecha"],
|
|
|
|
- "motivo": e["motivoPaquete"]["descripcion"]
|
|
|
|
- }))
|
|
|
|
- .toList()
|
|
|
|
- : [],
|
|
|
|
- response["resultado"][0]["ultimaBitacora"] != null
|
|
|
|
- ? response["resultado"][0]["ultimaBitacora"]
|
|
|
|
- ["entradaSalida"]
|
|
|
|
- : "E",
|
|
|
|
- true,
|
|
|
|
- response["resultado"][0]["ultimaBitacora"] != null
|
|
|
|
- ? response["resultado"][0]["ultimaBitacora"]
|
|
|
|
- ["idConsejoElectoral"]
|
|
|
|
- : 0,
|
|
|
|
- response["resultado"][0]["idTipoEleccion"])),
|
|
|
|
- );
|
|
|
|
- } catch (e) {
|
|
|
|
- print(e);
|
|
|
|
- } finally {
|
|
|
|
- if (mounted) setState(() => _loading = false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+class HomeScreen extends StatelessWidget {
|
|
|
|
+ const HomeScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
|
|
+ final homeViewModel = Provider.of<HomeViewModel>(context);
|
|
|
|
+ final opciones = homeViewModel.opciones;
|
|
String correo = Provider.of<LoginViewModel>(context).correo;
|
|
String correo = Provider.of<LoginViewModel>(context).correo;
|
|
- return Scaffold(
|
|
|
|
- backgroundColor: Colors.grey.shade200,
|
|
|
|
- appBar: AppBar(
|
|
|
|
- elevation: 0,
|
|
|
|
- title: const Text(
|
|
|
|
- 'Inicio',
|
|
|
|
- style: TextStyle(color: Colors.white),
|
|
|
|
|
|
+ return WillPopScope(
|
|
|
|
+ onWillPop: () async {
|
|
|
|
+ return false;
|
|
|
|
+ },
|
|
|
|
+ child: Scaffold(
|
|
|
|
+ drawer: AppDrawer(),
|
|
|
|
+ appBar: AppBar(
|
|
|
|
+ elevation: 0,
|
|
|
|
+ title: const Text(
|
|
|
|
+ 'Inicio',
|
|
|
|
+ style: TextStyle( color: Colors.white),
|
|
|
|
+ ),
|
|
|
|
+ iconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
+ actions: [usuarioHeader(correo)],
|
|
|
|
+ ),
|
|
|
|
+ body: GridView.builder(
|
|
|
|
+ gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
|
|
+ crossAxisCount: 1),
|
|
|
|
+ itemCount: opciones.length,
|
|
|
|
+ itemBuilder: (context, index) {
|
|
|
|
+ final opcion = opciones[index];
|
|
|
|
+ return Padding(
|
|
|
|
+ padding: const EdgeInsets.all(8.0),
|
|
|
|
+ child: InkWell(
|
|
|
|
+ onTap: () {
|
|
|
|
+ Navigator.of(context).push(
|
|
|
|
+ MaterialPageRoute(
|
|
|
|
+ builder: (context) => opcion['pantalla'],
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ child: Card(
|
|
|
|
+ surfaceTintColor: AppTheme.secondary,
|
|
|
|
+ elevation: 5,
|
|
|
|
+ child: Column(
|
|
|
|
+ children: [
|
|
|
|
+ Expanded(
|
|
|
|
+ child: Image(
|
|
|
|
+ image: AssetImage('assets/menu${index + 1}.png'),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ListTile(
|
|
|
|
+ title: Text(
|
|
|
|
+ opcion['opcion'],
|
|
|
|
+ style: const TextStyle(fontSize: 18),
|
|
|
|
+ ),
|
|
|
|
+ subtitle: Text(opcion['descripcion']),
|
|
|
|
+ ),
|
|
|
|
+ const SizedBox(
|
|
|
|
+ height: 5,
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ },
|
|
),
|
|
),
|
|
- iconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
- actions: [usuarioHeader(correo)],
|
|
|
|
),
|
|
),
|
|
- drawer: AppDrawer(),
|
|
|
|
- body: Column(children: [
|
|
|
|
- const SizedBox(height: 150),
|
|
|
|
- Center(
|
|
|
|
- child: Image.asset(
|
|
|
|
- "assets/Elecciones2024.png",
|
|
|
|
- height: 150,
|
|
|
|
- )),
|
|
|
|
- const SizedBox(height: 100),
|
|
|
|
- Center(
|
|
|
|
- child: GestureDetector(
|
|
|
|
- onTap: _scanner,
|
|
|
|
- child: CircleAvatar(
|
|
|
|
- radius: 100,
|
|
|
|
- child: _loading
|
|
|
|
- ? CircularProgressIndicator(
|
|
|
|
- valueColor:
|
|
|
|
- new AlwaysStoppedAnimation<Color>(Colors.white),
|
|
|
|
- )
|
|
|
|
- : const Icon(
|
|
|
|
- Icons.camera_alt,
|
|
|
|
- size: 100,
|
|
|
|
- )),
|
|
|
|
- )),
|
|
|
|
- ]),
|
|
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|