- 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>
178 lines
5.6 KiB
Dart
178 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'theme.dart';
|
|
import 'pages/control_acceso_page.dart';
|
|
import 'pages/monitoreo_alarma_page.dart';
|
|
import 'pages/inicio_page.dart' show InicioPage, InicioPageState;
|
|
import 'pages/perfil_usuario_page.dart';
|
|
import 'widgets/app_menu_button.dart';
|
|
|
|
class MainPage extends StatefulWidget {
|
|
final int initialIndex;
|
|
const MainPage({Key? key, this.initialIndex = 0}) : super(key: key);
|
|
|
|
@override
|
|
State<MainPage> createState() => _MainPageState();
|
|
}
|
|
|
|
class _MainPageState extends State<MainPage> {
|
|
late final PageController _pageController;
|
|
int _navSelected = 0;
|
|
final _inicioKey = GlobalKey<InicioPageState>();
|
|
|
|
List<Widget> get _pages => [
|
|
InicioPage(key: _inicioKey, onGoToPerfil: () => _onNavTap(3)),
|
|
const ControlAccesoPage(),
|
|
const MonitoreoAlarmaPage(),
|
|
const PerfilUsuarioPage(),
|
|
];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_navSelected = widget.initialIndex;
|
|
_pageController = PageController(initialPage: widget.initialIndex);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _onNavTap(int idx) {
|
|
if (idx == 0) _inicioKey.currentState?.recargar();
|
|
_pageController.animateToPage(
|
|
idx,
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeInOut,
|
|
);
|
|
}
|
|
|
|
void _onPageChanged(int idx) {
|
|
setState(() => _navSelected = idx);
|
|
}
|
|
|
|
String get _tituloActual {
|
|
switch (_navSelected) {
|
|
case 0: return 'INICIO';
|
|
case 1: return 'CONTROL DE ACCESO';
|
|
case 2: return 'ALARMAS';
|
|
case 3: return 'MI PERFIL';
|
|
default: return '';
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.surfaceLowest,
|
|
body: SafeArea(
|
|
bottom: false,
|
|
child: Column(
|
|
children: [
|
|
_header(),
|
|
Expanded(
|
|
child: PageView(
|
|
controller: _pageController,
|
|
onPageChanged: _onPageChanged,
|
|
children: _pages,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
bottomNavigationBar: _bottomNav(),
|
|
);
|
|
}
|
|
|
|
// ── Header compartido ──────────────────────────────────────────────────────
|
|
Widget _header() => Container(
|
|
height: 64,
|
|
color: AppColors.surfaceLow,
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(children: [
|
|
Image.asset('lib/recursos/logo_app.png', width: 30, height: 30),
|
|
const SizedBox(width: 12),
|
|
Text('SENTINEL ONE',
|
|
style: appHeadline(
|
|
size: 18,
|
|
weight: FontWeight.w900,
|
|
color: AppColors.primary,
|
|
spacing: 2.5)),
|
|
]),
|
|
Row(children: [
|
|
Text(_tituloActual,
|
|
style: appLabel(
|
|
size: 10,
|
|
weight: FontWeight.bold,
|
|
color: AppColors.onSurfaceVariant,
|
|
spacing: 1.5)),
|
|
const AppMenuButton(),
|
|
]),
|
|
],
|
|
),
|
|
);
|
|
|
|
// ── Bottom nav compartido ──────────────────────────────────────────────────
|
|
Widget _bottomNav() => Container(
|
|
padding: const EdgeInsets.only(
|
|
left: 16, right: 16, bottom: 28, top: 12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceLow.withOpacity(0.97),
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColors.onSurface.withOpacity(0.08),
|
|
offset: const Offset(0, -4),
|
|
blurRadius: 24,
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_navItem(Icons.home_outlined, 'INICIO', 0),
|
|
_navItem(Icons.lock_open, 'ACCESO', 1),
|
|
_navItem(Icons.notifications_active, 'ALARMAS', 2),
|
|
_navItem(Icons.person_outline, 'PERFIL', 3),
|
|
],
|
|
),
|
|
);
|
|
|
|
Widget _navItem(IconData icon, String label, int idx) {
|
|
final isActive = _navSelected == idx;
|
|
return GestureDetector(
|
|
onTap: () => _onNavTap(idx),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: isActive ? 18 : 10, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: isActive ? AppColors.primary : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
Icon(icon,
|
|
size: 22,
|
|
color: isActive
|
|
? AppColors.primaryContainer
|
|
: AppColors.onSurface.withOpacity(0.5)),
|
|
const SizedBox(height: 4),
|
|
Text(label,
|
|
style: appLabel(
|
|
size: 10,
|
|
weight: FontWeight.w600,
|
|
color: isActive
|
|
? AppColors.primaryContainer
|
|
: AppColors.onSurface.withOpacity(0.5),
|
|
spacing: 0.5)),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
}
|