feat: implementacion completa de 8 modulos, sincronizador centinel, mcp y bitacora de errores
This commit is contained in:
+208
-36
@@ -10,6 +10,7 @@ import 'pages/incidentes_page.dart';
|
||||
import 'pages/dispositivos_page.dart';
|
||||
import 'pages/reportes_page.dart';
|
||||
import 'pages/configuracion_page.dart';
|
||||
import 'services/sincronizador.dart';
|
||||
|
||||
class ShellPage extends StatefulWidget {
|
||||
const ShellPage({Key? key}) : super(key: key);
|
||||
@@ -53,6 +54,13 @@ class _ShellPageState extends State<ShellPage> {
|
||||
_cargarOperador();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Comentario explicativo: Detiene el ciclo periódico del sincronizador al destruir ShellPage
|
||||
Sincronizador.instance.detener();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _cargarOperador() async {
|
||||
final nombre = await ApiAuthService.instance.getNombre();
|
||||
final usuario = await ApiAuthService.instance.getUsuario() ?? '';
|
||||
@@ -60,6 +68,9 @@ class _ShellPageState extends State<ShellPage> {
|
||||
setState(() => _operadorNombre = nombre ?? usuario);
|
||||
await _sesionesDao.iniciarSesion(_operadorNombre, usuario);
|
||||
_verificarApi();
|
||||
|
||||
// Comentario explicativo: Inicia el ciclo periódico de sincronización automática en segundo plano
|
||||
Sincronizador.instance.iniciar(intervaloSegundos: 30);
|
||||
}
|
||||
|
||||
Future<void> _verificarApi() async {
|
||||
@@ -90,61 +101,166 @@ class _ShellPageState extends State<ShellPage> {
|
||||
),
|
||||
);
|
||||
if (ok != true) return;
|
||||
Sincronizador.instance.detener();
|
||||
await _sesionesDao.cerrarSesion();
|
||||
await ApiAuthService.instance.logout();
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pushReplacementNamed('/login');
|
||||
}
|
||||
|
||||
// Comentario explicativo: Soporte de layout adaptativo responsivo.
|
||||
// En escritorio/pantallas grandes (ancho >= 720px) mantiene el Sidebar fijo de 220px original.
|
||||
// En pantallas móviles (< 720px), colapsa el sidebar a un Drawer y BottomNavigationBar
|
||||
// para permitir una experiencia óptima y capturas de pantalla móviles limpias sin desbordamiento.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ancho = MediaQuery.of(context).size.width;
|
||||
final esMovil = ancho < 720;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surfaceLowest,
|
||||
body: Column(children: [
|
||||
_header(),
|
||||
Expanded(
|
||||
child: Row(children: [
|
||||
_sidebar(),
|
||||
const VerticalDivider(width: 1, color: AppColors.outlineVariant),
|
||||
Expanded(
|
||||
child: IndexedStack(
|
||||
index: _indice,
|
||||
children: _paginas,
|
||||
drawer: esMovil
|
||||
? Drawer(
|
||||
backgroundColor: AppColors.surfaceLow,
|
||||
child: SafeArea(
|
||||
child: Column(children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Row(children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primaryContainer,
|
||||
),
|
||||
child: const Icon(Icons.shield, color: AppColors.primary, size: 18),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text('CENTRO DE MONITOREO',
|
||||
style: appHeadline(
|
||||
size: 13,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primary,
|
||||
spacing: 1.2)),
|
||||
]),
|
||||
),
|
||||
const Divider(color: AppColors.outlineVariant, height: 1),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
itemCount: _navItems.length,
|
||||
itemBuilder: (_, i) => _navTile(i, cerrarDrawerAlTocar: true),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
)
|
||||
: null,
|
||||
body: SafeArea(
|
||||
top: esMovil,
|
||||
bottom: false,
|
||||
child: Column(children: [
|
||||
_header(esMovil: esMovil),
|
||||
Expanded(
|
||||
child: esMovil
|
||||
? IndexedStack(
|
||||
index: _indice,
|
||||
children: _paginas,
|
||||
)
|
||||
: Row(children: [
|
||||
_sidebar(),
|
||||
const VerticalDivider(width: 1, color: AppColors.outlineVariant),
|
||||
Expanded(
|
||||
child: IndexedStack(
|
||||
index: _indice,
|
||||
children: _paginas,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
bottomNavigationBar: esMovil
|
||||
? BottomNavigationBar(
|
||||
// Comentario explicativo: Mapeo de índices de navegación móvil:
|
||||
// 0: Dashboard, 1: Monitoreo, 2: Clientes, 4: Incidentes
|
||||
currentIndex: _indice == 4 ? 3 : (_indice < 3 ? _indice : 0),
|
||||
backgroundColor: AppColors.surfaceLow,
|
||||
selectedItemColor: AppColors.primary,
|
||||
unselectedItemColor: AppColors.onSurfaceVariant,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
selectedFontSize: 11,
|
||||
unselectedFontSize: 10,
|
||||
onTap: (i) {
|
||||
const indicesMovil = [0, 1, 2, 4];
|
||||
setState(() => _indice = indicesMovil[i]);
|
||||
},
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
activeIcon: Icon(Icons.dashboard),
|
||||
label: 'Dashboard',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.track_changes_outlined),
|
||||
activeIcon: Icon(Icons.track_changes),
|
||||
label: 'Monitoreo',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.business_outlined),
|
||||
activeIcon: Icon(Icons.business),
|
||||
label: 'Clientes',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.assignment_outlined),
|
||||
activeIcon: Icon(Icons.assignment),
|
||||
label: 'Incidentes',
|
||||
),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
// ── Header ──────────────────────────────────────────────────────────────────
|
||||
Widget _header() => Container(
|
||||
Widget _header({bool esMovil = false}) => Container(
|
||||
height: 56,
|
||||
color: AppColors.surfaceLow,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
padding: EdgeInsets.symmetric(horizontal: esMovil ? 12 : 24),
|
||||
child: Row(children: [
|
||||
if (esMovil)
|
||||
Builder(
|
||||
builder: (ctx) => IconButton(
|
||||
icon: const Icon(Icons.menu, color: AppColors.onSurface, size: 22),
|
||||
tooltip: 'Menú de navegación',
|
||||
onPressed: () => Scaffold.of(ctx).openDrawer(),
|
||||
),
|
||||
),
|
||||
// Logo + nombre app
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primaryContainer,
|
||||
),
|
||||
child: const Icon(Icons.shield, color: AppColors.primary, size: 18),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text('CENTRO DE MONITOREO',
|
||||
style: appHeadline(
|
||||
size: 14,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primary,
|
||||
spacing: 1.5)),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
esMovil ? 'MONITOREO' : 'CENTRO DE MONITOREO',
|
||||
style: appHeadline(
|
||||
size: esMovil ? 13 : 14,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primary,
|
||||
spacing: 1.2),
|
||||
),
|
||||
const Spacer(),
|
||||
// Estado API
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: (_apiConectada ? AppColors.primaryContainer : AppColors.surfaceHighest),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
@@ -162,34 +278,85 @@ class _ShellPageState extends State<ShellPage> {
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
_apiConectada ? 'API conectada' : 'Sin conexión',
|
||||
_apiConectada ? 'Online' : 'Offline',
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
color: _apiConectada ? AppColors.primary : AppColors.outline),
|
||||
),
|
||||
]),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
// Comentario explicativo: Indicador visual prioritario de alarmas críticas en el header con salto directo a Monitoreo
|
||||
ValueListenableBuilder<int>(
|
||||
valueListenable: Sincronizador.instance.criticalAlarmsCount,
|
||||
builder: (ctx, count, _) {
|
||||
if (count == 0) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 6),
|
||||
child: InkWell(
|
||||
onTap: () => setState(() => _indice = 1),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.alarmaActiva.withAlpha(40),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: AppColors.alarmaActiva),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.warning_amber_rounded, size: 14, color: AppColors.alarmaActiva),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'$count CRÍTICA${count > 1 ? 'S' : ''}',
|
||||
style: appHeadline(size: 11, color: AppColors.alarmaActiva, weight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
// Comentario explicativo: Botón de sincronización con indicador giratorio de actividad
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: Sincronizador.instance.isSyncing,
|
||||
builder: (ctx, syncing, _) => IconButton(
|
||||
icon: syncing
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: AppColors.primary),
|
||||
)
|
||||
: const Icon(Icons.sync, color: AppColors.outline, size: 20),
|
||||
tooltip: syncing ? 'Sincronizando con Centinel...' : 'Sincronizar ahora',
|
||||
onPressed: syncing ? null : () => Sincronizador.instance.sincronizarAhora(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Operador
|
||||
Row(children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primaryContainer,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_operadorNombre.isNotEmpty ? _operadorNombre[0].toUpperCase() : 'O',
|
||||
style: appHeadline(size: 14, weight: FontWeight.bold, color: AppColors.primary),
|
||||
style: appHeadline(size: 13, weight: FontWeight.bold, color: AppColors.primary),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_operadorNombre, style: appLabel(size: 13, color: AppColors.onSurface)),
|
||||
if (!esMovil) ...[
|
||||
const SizedBox(width: 8),
|
||||
Text(_operadorNombre, style: appLabel(size: 13, color: AppColors.onSurface)),
|
||||
],
|
||||
]),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout, color: AppColors.outline, size: 20),
|
||||
tooltip: 'Cerrar sesión',
|
||||
@@ -214,7 +381,7 @@ class _ShellPageState extends State<ShellPage> {
|
||||
]),
|
||||
);
|
||||
|
||||
Widget _navTile(int i) {
|
||||
Widget _navTile(int i, {bool cerrarDrawerAlTocar = false}) {
|
||||
final item = _navItems[i];
|
||||
final activo = _indice == i;
|
||||
return Padding(
|
||||
@@ -224,7 +391,12 @@ class _ShellPageState extends State<ShellPage> {
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () => setState(() => _indice = i),
|
||||
onTap: () {
|
||||
setState(() => _indice = i);
|
||||
if (cerrarDrawerAlTocar) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 160),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 11),
|
||||
|
||||
Reference in New Issue
Block a user