feat: eventos BD en inicio, DemoDataService y recarga al cambiar tab
- InicioPage conectada a BD: eventos reales, métricas suscripción y nodos - Eventos del log cargan desde EventosDao (getRecientes limit 6) - Métricas: estado suscripción (PROTEGIDO/POR VENCER/SUSPENDIDO/VENCIDO) - NodosDao: nuevo método contarActivos() - InicioPageState pública + método recargar() vía GlobalKey - MainPage: llama recargar() al volver al tab INICIO - DemoDataService: singleton que carga eventos, alarmas, mensajes, accesos y sesiones de prueba - Settings: botón "Datos de demostración" con diálogo de confirmación Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4d3d298773
commit
80442a1269
@@ -6,6 +6,7 @@ import 'package:path/path.dart' as p;
|
||||
import '../theme.dart';
|
||||
import '../db/database_helper.dart';
|
||||
import '../services/sincronizador.dart';
|
||||
import '../services/demo_data_service.dart';
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
const SettingsPage({Key? key}) : super(key: key);
|
||||
@@ -21,6 +22,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
|
||||
bool _iniciandoBd = false;
|
||||
bool _sincronizando = false;
|
||||
bool _cargandoDemo = false;
|
||||
|
||||
// ── Build ──────────────────────────────────────────────────────────────────
|
||||
@override
|
||||
@@ -87,6 +89,15 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
cargando: _sincronizando,
|
||||
onTap: _iniciarSincronizacion,
|
||||
),
|
||||
_divider(),
|
||||
_accionItem(
|
||||
icon: Icons.science_outlined,
|
||||
iconColor: AppColors.tertiary,
|
||||
titulo: 'Datos de demostración',
|
||||
subtitulo: 'Carga eventos, alarmas, mensajes y accesos de prueba',
|
||||
cargando: _cargandoDemo,
|
||||
onTap: _cargarDemostracion,
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
@@ -236,6 +247,52 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Datos de demostración ──────────────────────────────────────────────────
|
||||
Future<void> _cargarDemostracion() async {
|
||||
final confirmar = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Datos de demostración',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700)),
|
||||
content: Text(
|
||||
'Se reemplazarán los eventos, alarmas, mensajes, accesos y sesiones '
|
||||
'actuales con datos de prueba.\n\nLos usuarios, zonas, clientes y '
|
||||
'suscripciones no se modifican.',
|
||||
style: appLabel(size: 13),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(size: 13,
|
||||
color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text('Cargar',
|
||||
style: appLabel(size: 13,
|
||||
weight: FontWeight.bold, color: AppColors.tertiary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmar != true) return;
|
||||
setState(() => _cargandoDemo = true);
|
||||
|
||||
try {
|
||||
await DemoDataService.instance.cargarDatos();
|
||||
if (!mounted) return;
|
||||
_snack('Datos de demostración cargados', esError: false);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_snack('Error al cargar datos: $e');
|
||||
} finally {
|
||||
if (mounted) setState(() => _cargandoDemo = false);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Helpers de UI ──────────────────────────────────────────────────────────
|
||||
void _snack(String msg, {bool esError = true}) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
|
||||
Reference in New Issue
Block a user