feat: commit inicial — Central Monitoreo v1.0.0
- OperadorLoginPage con auth WebControl 2 pasos (empresas → login) - ShellPage: sidebar 220px + IndexedStack + header con estado API - DashboardPage: stat cards, feed alarmas, clientes, incidentes (timer 30s) - ApiAuthService: flujo real con email + paswd + dba → token + apiKey - DB SQLite v1: 7 tablas + 7 DAOs completos - theme.dart: AppColors, appHeadline (Manrope), appLabel (Inter) - Logo app: escudo radar neón (SVG + PNG 512px) en lib/recursos/ - desplegar.sh: build release Linux + upload a siax-system.net - agents.md: estado completo + objetivos futuros documentados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,263 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'theme.dart';
|
||||
import 'services/api_auth_service.dart';
|
||||
import 'db/dao/sesiones_dao.dart';
|
||||
import 'pages/dashboard_page.dart';
|
||||
import 'pages/monitoreo_page.dart';
|
||||
import 'pages/clientes_page.dart';
|
||||
import 'pages/operadores_page.dart';
|
||||
import 'pages/incidentes_page.dart';
|
||||
import 'pages/dispositivos_page.dart';
|
||||
import 'pages/reportes_page.dart';
|
||||
import 'pages/configuracion_page.dart';
|
||||
|
||||
class ShellPage extends StatefulWidget {
|
||||
const ShellPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ShellPage> createState() => _ShellPageState();
|
||||
}
|
||||
|
||||
class _ShellPageState extends State<ShellPage> {
|
||||
int _indice = 0;
|
||||
String _operadorNombre = 'Operador';
|
||||
bool _apiConectada = false;
|
||||
|
||||
final _sesionesDao = SesionesDao();
|
||||
|
||||
static const _paginas = [
|
||||
DashboardPage(),
|
||||
MonitoreoPage(),
|
||||
ClientesPage(),
|
||||
OperadoresPage(),
|
||||
IncidentesPage(),
|
||||
DispositivosPage(),
|
||||
ReportesPage(),
|
||||
ConfiguracionPage(),
|
||||
];
|
||||
|
||||
static const _navItems = [
|
||||
_NavItem(Icons.dashboard_outlined, Icons.dashboard, 'Dashboard'),
|
||||
_NavItem(Icons.track_changes_outlined, Icons.track_changes, 'Monitoreo'),
|
||||
_NavItem(Icons.business_outlined, Icons.business, 'Clientes'),
|
||||
_NavItem(Icons.group_outlined, Icons.group, 'Operadores'),
|
||||
_NavItem(Icons.assignment_outlined, Icons.assignment, 'Incidentes'),
|
||||
_NavItem(Icons.devices_outlined, Icons.devices, 'Dispositivos'),
|
||||
_NavItem(Icons.bar_chart_outlined, Icons.bar_chart, 'Reportes'),
|
||||
_NavItem(Icons.settings_outlined, Icons.settings, 'Configuración'),
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cargarOperador();
|
||||
}
|
||||
|
||||
Future<void> _cargarOperador() async {
|
||||
final nombre = await ApiAuthService.instance.getNombre();
|
||||
final usuario = await ApiAuthService.instance.getUsuario() ?? '';
|
||||
if (!mounted) return;
|
||||
setState(() => _operadorNombre = nombre ?? usuario);
|
||||
await _sesionesDao.iniciarSesion(_operadorNombre, usuario);
|
||||
_verificarApi();
|
||||
}
|
||||
|
||||
Future<void> _verificarApi() async {
|
||||
final ok = await ApiAuthService.instance.isAuthenticated();
|
||||
if (!mounted) return;
|
||||
setState(() => _apiConectada = ok);
|
||||
}
|
||||
|
||||
Future<void> _cerrarSesion() async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Cerrar sesión',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700)),
|
||||
content: Text('¿Finalizar el turno y cerrar sesión?',
|
||||
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('CERRAR', style: appLabel(weight: FontWeight.bold, color: AppColors.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (ok != true) return;
|
||||
await _sesionesDao.cerrarSesion();
|
||||
await ApiAuthService.instance.logout();
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pushReplacementNamed('/login');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Header ──────────────────────────────────────────────────────────────────
|
||||
Widget _header() => Container(
|
||||
height: 56,
|
||||
color: AppColors.surfaceLow,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Row(children: [
|
||||
// Logo + nombre app
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: 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 Spacer(),
|
||||
// Estado API
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: (_apiConectada ? AppColors.primaryContainer : AppColors.surfaceHighest),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _apiConectada
|
||||
? const Color(0xFF4CAF50)
|
||||
: AppColors.outline,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
_apiConectada ? 'API conectada' : 'Sin conexión',
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
color: _apiConectada ? AppColors.primary : AppColors.outline),
|
||||
),
|
||||
]),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
// Operador
|
||||
Row(children: [
|
||||
Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: 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),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_operadorNombre, style: appLabel(size: 13, color: AppColors.onSurface)),
|
||||
]),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout, color: AppColors.outline, size: 20),
|
||||
tooltip: 'Cerrar sesión',
|
||||
onPressed: _cerrarSesion,
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
// ── Sidebar ─────────────────────────────────────────────────────────────────
|
||||
Widget _sidebar() => Container(
|
||||
width: 220,
|
||||
color: AppColors.surfaceLow,
|
||||
child: Column(children: [
|
||||
const SizedBox(height: 8),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
itemCount: _navItems.length,
|
||||
itemBuilder: (_, i) => _navTile(i),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
Widget _navTile(int i) {
|
||||
final item = _navItems[i];
|
||||
final activo = _indice == i;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () => setState(() => _indice = i),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 160),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 11),
|
||||
decoration: BoxDecoration(
|
||||
color: activo ? AppColors.primaryContainer : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Row(children: [
|
||||
Icon(
|
||||
activo ? item.iconActivo : item.icon,
|
||||
size: 20,
|
||||
color: activo ? AppColors.primary : AppColors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
item.label,
|
||||
style: appLabel(
|
||||
size: 13,
|
||||
weight: activo ? FontWeight.w600 : FontWeight.normal,
|
||||
color: activo ? AppColors.primary : AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NavItem {
|
||||
final IconData icon;
|
||||
final IconData iconActivo;
|
||||
final String label;
|
||||
const _NavItem(this.icon, this.iconActivo, this.label);
|
||||
}
|
||||
Reference in New Issue
Block a user