feat: ApiAuthService + Sincronizador reescritos para WebControl/Centinel
- ApiAuthService: login WebControl → guarda jwt + apiKey + db_tenant - Sincronizador: pull alarmas/zonas/usuarios/mensajes/banners + push pendientes - DAOs: métodos adicionales en alarmas, eventos, usuarios - Páginas actualizadas: ConectarProveedorPage, ControlAccesoPage, MensajeríaPage, MonitoreoAlarmaPage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4724f84b04
commit
efa4a792f4
@@ -3,9 +3,11 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/database_helper.dart';
|
||||
import '../services/api_auth_service.dart';
|
||||
|
||||
/// Pantalla de onboarding: el cliente la ve la primera vez que abre la app.
|
||||
/// Guarda la URL y usuario del proveedor en `configuracion` y navega al login.
|
||||
/// Pantalla de onboarding: el operador ingresa sus credenciales de WebControl
|
||||
/// (api.siax-system.net). La app autentica, recibe apiKey + db_tenant y los
|
||||
/// guarda en SharedPreferences para todas las llamadas a API_CENTINEL_SECURITY.
|
||||
class ConectarProveedorPage extends StatefulWidget {
|
||||
const ConectarProveedorPage({Key? key}) : super(key: key);
|
||||
|
||||
@@ -18,45 +20,49 @@ class _ConectarProveedorPageState extends State<ConectarProveedorPage> {
|
||||
bool _guardando = false;
|
||||
bool _obscurePass = true;
|
||||
|
||||
final _urlCtrl = TextEditingController();
|
||||
final _usuarioCtrl = TextEditingController();
|
||||
final _passCtrl = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_urlCtrl.dispose();
|
||||
_usuarioCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _guardarYContinuar() async {
|
||||
final url = _urlCtrl.text.trim();
|
||||
final usuario = _usuarioCtrl.text.trim();
|
||||
final pass = _passCtrl.text;
|
||||
|
||||
if (url.isEmpty || usuario.isEmpty) {
|
||||
_snack('Completa la URL y el usuario');
|
||||
if (usuario.isEmpty || pass.isEmpty) {
|
||||
_snack('Completa usuario y contraseña');
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _guardando = true);
|
||||
|
||||
try {
|
||||
final ok = await ApiAuthService.instance.login(usuario, pass);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (!ok) {
|
||||
_snack('Credenciales incorrectas o sin conexión');
|
||||
return;
|
||||
}
|
||||
|
||||
// Guardar usuario en configuracion para referencia local
|
||||
final db = await DatabaseHelper.instance.db;
|
||||
await db.insert('configuracion',
|
||||
{'clave': 'api_base_url', 'valor': url},
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
await db.insert('configuracion',
|
||||
{'clave': 'api_usuario', 'valor': usuario},
|
||||
conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
_snack('Configuración guardada', esError: false);
|
||||
_snack('Conexión establecida', esError: false);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_snack('Error al guardar: $e');
|
||||
_snack('Error: $e');
|
||||
} finally {
|
||||
if (mounted) setState(() => _guardando = false);
|
||||
}
|
||||
@@ -172,8 +178,8 @@ class _ConectarProveedorPageState extends State<ConectarProveedorPage> {
|
||||
size: 20, weight: FontWeight.w800, color: AppColors.primary)),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Para comenzar, conecta tu dispositivo '
|
||||
'con tu proveedor de servicios de monitoreo.',
|
||||
'Ingresa tus credenciales de Telcotronics WebControl '
|
||||
'para activar el monitoreo en tiempo real.',
|
||||
textAlign: TextAlign.center,
|
||||
style: appLabel(size: 14, color: AppColors.onSurfaceVariant),
|
||||
),
|
||||
@@ -184,9 +190,9 @@ class _ConectarProveedorPageState extends State<ConectarProveedorPage> {
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => setState(() => _mostrarFormulario = true),
|
||||
icon: const Icon(Icons.link, size: 20,
|
||||
icon: const Icon(Icons.login, size: 20,
|
||||
color: AppColors.primaryContainer),
|
||||
label: Text('CONECTAR CON MI PROVEEDOR',
|
||||
label: Text('INICIAR SESIÓN EN WEBCONTROL',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -203,8 +209,8 @@ class _ConectarProveedorPageState extends State<ConectarProveedorPage> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Solicita los datos de conexión a tu proveedor '
|
||||
'de servicios de monitoreo.',
|
||||
'Tus credenciales son las mismas que usas '
|
||||
'en el portal Telcotronics WebControl.',
|
||||
textAlign: TextAlign.center,
|
||||
style: appLabel(size: 11, color: AppColors.outlineVariant),
|
||||
),
|
||||
@@ -229,25 +235,17 @@ class _ConectarProveedorPageState extends State<ConectarProveedorPage> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
Text('Datos del proveedor',
|
||||
Text('Credenciales WebControl',
|
||||
style: appHeadline(size: 17, weight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text('Ingresa los datos que te entregó tu proveedor de monitoreo.',
|
||||
Text('Las mismas credenciales del portal Telcotronics.',
|
||||
style: appLabel(size: 12, color: AppColors.onSurfaceVariant)),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
_campo(
|
||||
controller: _urlCtrl,
|
||||
label: 'URL del servidor',
|
||||
hint: 'https://monitor.miproveedor.com',
|
||||
icono: Icons.link,
|
||||
tipo: TextInputType.url,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_campo(
|
||||
controller: _usuarioCtrl,
|
||||
label: 'Usuario / Código de cliente',
|
||||
hint: 'cliente001',
|
||||
label: 'Usuario o email',
|
||||
hint: 'operador@empresa.com',
|
||||
icono: Icons.person_outline,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
//agregar un boton para registrar usuarios y dale acceso por tiempo y areas
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/accesos_dao.dart';
|
||||
import '../db/dao/usuarios_dao.dart';
|
||||
import '../models/usuario.dart';
|
||||
import 'registrar_usuario_page.dart';
|
||||
|
||||
class ControlAccesoPage extends StatefulWidget {
|
||||
const ControlAccesoPage({Key? key}) : super(key: key);
|
||||
@@ -17,7 +18,9 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
bool _serverBloqueado = true;
|
||||
|
||||
final _dao = AccesosDao();
|
||||
final _usuariosDao = UsuariosDao();
|
||||
List<Map<String, dynamic>> _accesos = [];
|
||||
List<Usuario> _usuarios = [];
|
||||
bool _cargando = true;
|
||||
|
||||
@override
|
||||
@@ -29,13 +32,29 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
Future<void> _cargar() async {
|
||||
setState(() => _cargando = true);
|
||||
try {
|
||||
final lista = await _dao.getRecientesConDetalle(limit: 20);
|
||||
final results = await Future.wait([
|
||||
_dao.getRecientesConDetalle(limit: 20),
|
||||
_usuariosDao.getActivos(),
|
||||
]);
|
||||
if (!mounted) return;
|
||||
setState(() => _accesos = lista);
|
||||
setState(() {
|
||||
_accesos = results[0] as List<Map<String, dynamic>>;
|
||||
_usuarios = results[1] as List<Usuario>;
|
||||
});
|
||||
} catch (_) {}
|
||||
if (mounted) setState(() => _cargando = false);
|
||||
}
|
||||
|
||||
void _abrirRegistro() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => const RegistrarUsuarioPage(),
|
||||
),
|
||||
).then((ok) { if (ok == true) _cargar(); });
|
||||
}
|
||||
|
||||
String _horaCorta(String iso) {
|
||||
try {
|
||||
final dt = DateTime.parse(iso).toLocal();
|
||||
@@ -53,24 +72,40 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _cargar,
|
||||
color: AppColors.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
primary: false,
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_encabezado(),
|
||||
const SizedBox(height: 32),
|
||||
_gridEntradas(),
|
||||
const SizedBox(height: 40),
|
||||
_registroAcceso(),
|
||||
const SizedBox(height: 24),
|
||||
_snapshotCamara(),
|
||||
],
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: _abrirRegistro,
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: AppColors.primaryContainer,
|
||||
icon: const Icon(Icons.person_add_alt_1, size: 20),
|
||||
label: Text('Registrar Usuario',
|
||||
style: appLabel(
|
||||
size: 13,
|
||||
weight: FontWeight.bold,
|
||||
color: AppColors.primaryContainer)),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _cargar,
|
||||
color: AppColors.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
primary: false,
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 96),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_encabezado(),
|
||||
const SizedBox(height: 32),
|
||||
_gridEntradas(),
|
||||
const SizedBox(height: 40),
|
||||
_usuariosRegistrados(),
|
||||
const SizedBox(height: 40),
|
||||
_registroAcceso(),
|
||||
const SizedBox(height: 24),
|
||||
_snapshotCamara(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -291,6 +326,215 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
]),
|
||||
);
|
||||
|
||||
// ── Usuarios registrados ────────────────────────────────────────────────────
|
||||
Widget _usuariosRegistrados() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Usuarios con Acceso',
|
||||
style: appHeadline(size: 20, weight: FontWeight.bold)),
|
||||
Text('${_usuarios.length} activo${_usuarios.length == 1 ? '' : 's'}',
|
||||
style: appLabel(size: 12, color: AppColors.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_cargando)
|
||||
const Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: AppColors.primary),
|
||||
))
|
||||
else if (_usuarios.isEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(children: [
|
||||
const Icon(Icons.group_outlined,
|
||||
color: AppColors.outlineVariant, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text('Sin usuarios registrados',
|
||||
style: appLabel(
|
||||
size: 13, color: AppColors.outlineVariant)),
|
||||
Text('Usa el botón + para agregar',
|
||||
style:
|
||||
appLabel(size: 11, color: AppColors.outlineVariant)),
|
||||
]),
|
||||
)
|
||||
else
|
||||
..._usuarios.map((u) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: _cardUsuario(u),
|
||||
)),
|
||||
],
|
||||
);
|
||||
|
||||
static const _nivelLabels = ['', 'Visitante', 'Empleado', 'Supervisor', 'Admin', 'Super Admin'];
|
||||
static const _nivelColors = [
|
||||
Colors.transparent,
|
||||
AppColors.outline,
|
||||
AppColors.secondary,
|
||||
AppColors.primary,
|
||||
AppColors.tertiary,
|
||||
AppColors.error,
|
||||
];
|
||||
|
||||
Widget _cardUsuario(Usuario u) {
|
||||
final nivel = u.nivelAcceso.clamp(1, 5);
|
||||
final nColor = _nivelColors[nivel];
|
||||
final nLabel = _nivelLabels[nivel];
|
||||
final fechaFin = u.fechaFin != null
|
||||
? _formatFecha(u.fechaFin!)
|
||||
: null;
|
||||
final vencido = u.fechaFin != null &&
|
||||
DateTime.tryParse(u.fechaFin!)?.isBefore(DateTime.now()) == true;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: vencido
|
||||
? AppColors.error.withOpacity(0.3)
|
||||
: AppColors.surfaceHighest,
|
||||
),
|
||||
),
|
||||
child: Row(children: [
|
||||
// Avatar
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: nColor.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: nColor.withOpacity(0.3)),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(u.iniciales,
|
||||
style: appHeadline(
|
||||
size: 15, weight: FontWeight.bold, color: nColor)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: Text(u.nombre,
|
||||
style:
|
||||
appHeadline(size: 14, weight: FontWeight.w600)),
|
||||
),
|
||||
// Badge nivel
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: nColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text('N$nivel · $nLabel',
|
||||
style: appLabel(
|
||||
size: 10,
|
||||
weight: FontWeight.bold,
|
||||
color: nColor)),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 4),
|
||||
Row(children: [
|
||||
Icon(Icons.calendar_today,
|
||||
size: 11, color: AppColors.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
fechaFin != null
|
||||
? 'Hasta $fechaFin${vencido ? ' · VENCIDO' : ''}'
|
||||
: 'Sin vencimiento',
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
color: vencido
|
||||
? AppColors.error
|
||||
: AppColors.onSurfaceVariant),
|
||||
),
|
||||
if (u.areas != null && u.areas!.isNotEmpty) ...[
|
||||
const SizedBox(width: 10),
|
||||
Icon(Icons.place_outlined,
|
||||
size: 11, color: AppColors.onSurfaceVariant),
|
||||
const SizedBox(width: 3),
|
||||
Expanded(
|
||||
child: Text(
|
||||
u.areas!.replaceAll(',', ', '),
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
color: AppColors.onSurfaceVariant),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
]),
|
||||
]),
|
||||
),
|
||||
// Botón desactivar
|
||||
IconButton(
|
||||
icon: const Icon(Icons.person_off_outlined,
|
||||
color: AppColors.outline, size: 18),
|
||||
tooltip: 'Desactivar acceso',
|
||||
onPressed: () => _confirmarDesactivar(u),
|
||||
padding: const EdgeInsets.all(8),
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatFecha(String iso) {
|
||||
try {
|
||||
final dt = DateTime.parse(iso).toLocal();
|
||||
return '${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year}';
|
||||
} catch (_) {
|
||||
return '—';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _confirmarDesactivar(Usuario u) async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Desactivar acceso',
|
||||
style: appHeadline(
|
||||
size: 15, weight: FontWeight.w700, color: AppColors.error)),
|
||||
content: Text(
|
||||
'Se revocará el acceso de "${u.nombre}". Esta acción puede revertirse desde el servidor.',
|
||||
style: appLabel(size: 13, color: AppColors.onSurface),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text('DESACTIVAR',
|
||||
style: appLabel(
|
||||
weight: FontWeight.bold, color: AppColors.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok != true) return;
|
||||
await _usuariosDao.desactivar(u.id);
|
||||
_cargar();
|
||||
}
|
||||
|
||||
// ── Registro de acceso ──────────────────────────────────────────────────────
|
||||
Widget _registroAcceso() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -457,12 +701,12 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
Positioned(
|
||||
left: 40,
|
||||
top: 20,
|
||||
child: _cctv_box(
|
||||
child: _cctvBox(
|
||||
80, 60, AppColors.primary.withOpacity(0.15))),
|
||||
Positioned(
|
||||
right: 60,
|
||||
top: 40,
|
||||
child: _cctv_box(
|
||||
child: _cctvBox(
|
||||
50, 40, AppColors.primary.withOpacity(0.08))),
|
||||
// Overlay oscuro inferior
|
||||
Container(
|
||||
@@ -507,7 +751,7 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
),
|
||||
);
|
||||
|
||||
Widget _cctv_box(double w, double h, Color color) => Container(
|
||||
Widget _cctvBox(double w, double h, Color color) => Container(
|
||||
width: w,
|
||||
height: h,
|
||||
decoration: BoxDecoration(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/mensajes_dao.dart';
|
||||
import '../db/dao/eventos_dao.dart';
|
||||
import '../models/mensaje.dart';
|
||||
import 'llamada_page.dart';
|
||||
|
||||
@@ -16,6 +17,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
final _inputController = TextEditingController();
|
||||
final _scrollController = ScrollController();
|
||||
final _dao = MensajesDao();
|
||||
final _eventosDao = EventosDao();
|
||||
|
||||
List<Mensaje> _mensajes = [];
|
||||
|
||||
@@ -159,16 +161,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
icon: Icons.warning_rounded,
|
||||
label: 'PÁNICO',
|
||||
labelBoton: 'ACTIVAR',
|
||||
onTap: () async {
|
||||
final m = Mensaje(
|
||||
texto: 'ALERTA DE PÁNICO ACTIVADA. Requiero asistencia inmediata.',
|
||||
esMio: true,
|
||||
hora: _horaActual(),
|
||||
timestamp: DateTime.now().toIso8601String(),
|
||||
);
|
||||
await _dao.insert(m);
|
||||
await _cargar();
|
||||
},
|
||||
onTap: _activarPanico,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
@@ -179,16 +172,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
icon: Icons.headset_mic_rounded,
|
||||
label: 'SOPORTE',
|
||||
labelBoton: 'CONTACTAR',
|
||||
onTap: () async {
|
||||
final m = Mensaje(
|
||||
texto: 'Hola, necesito asistencia técnica.',
|
||||
esMio: true,
|
||||
hora: _horaActual(),
|
||||
timestamp: DateTime.now().toIso8601String(),
|
||||
);
|
||||
await _dao.insert(m);
|
||||
await _cargar();
|
||||
},
|
||||
onTap: _solicitarSoporte,
|
||||
),
|
||||
),
|
||||
]),
|
||||
@@ -236,9 +220,70 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
]),
|
||||
);
|
||||
|
||||
Future<void> _activarPanico() async {
|
||||
final confirmar = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Confirmar Alerta de Pánico',
|
||||
style: appHeadline(
|
||||
size: 16, weight: FontWeight.w700, color: AppColors.error)),
|
||||
content: Text(
|
||||
'Se registrará una alerta de pánico de severidad máxima y se notificará a la central cuando el sistema se sincronice.',
|
||||
style: appLabel(size: 13, color: AppColors.onSurface),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text('ACTIVAR',
|
||||
style: appLabel(
|
||||
weight: FontWeight.bold, color: AppColors.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmar != true) return;
|
||||
await _eventosDao.registrar(
|
||||
tipo: 'alerta',
|
||||
titulo: 'ALERTA DE PANICO — Severidad maxima',
|
||||
descripcion:
|
||||
'Operador activó alarma de pánico. Requiere atención inmediata de la central.',
|
||||
);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppColors.error,
|
||||
content: Text('Alerta de pánico registrada',
|
||||
style: appLabel(color: Colors.white, weight: FontWeight.bold)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _solicitarSoporte() async {
|
||||
await _eventosDao.registrar(
|
||||
tipo: 'notificacion',
|
||||
titulo: 'Solicitud de soporte tecnico',
|
||||
descripcion: 'Operador solicitó asistencia técnica a la central.',
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => const LlamadaPage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _horaActual() {
|
||||
final t = TimeOfDay.now();
|
||||
return '${t.hour.toString().padLeft(2, '0')}:${t.minute.toString().padLeft(2, '0')}';
|
||||
final now = DateTime.now();
|
||||
return '${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
// ── Lista de mensajes ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/alarmas_dao.dart';
|
||||
import 'alarmas_page.dart';
|
||||
|
||||
class MonitoreoAlarmaPage extends StatefulWidget {
|
||||
const MonitoreoAlarmaPage({Key? key}) : super(key: key);
|
||||
@@ -310,7 +311,11 @@ class _MonitoreoAlarmaPageState extends State<MonitoreoAlarmaPage>
|
||||
)),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const AlarmasPage()),
|
||||
).then((_) => _cargar()),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: color,
|
||||
onPrimary: Colors.white,
|
||||
|
||||
Reference in New Issue
Block a user