MainPage con IndexedStack, bottom nav (INICIO/ACCESO/ALARMAS/PERFIL), header compartido con logo SENTINEL ONE y título de sección. AppMenuButton con Configuración, Sincronización, Términos y Privacidad. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
174 lines
5.6 KiB
Dart
174 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';
|
||
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 int _index;
|
||
// Guardamos también qué ítem del nav está "seleccionado visualmente"
|
||
// (INICIO y ALARMAS apuntan al mismo índice del stack)
|
||
late int _navSelected;
|
||
|
||
static const _pages = [
|
||
InicioPage(), // 0 – INICIO
|
||
ControlAccesoPage(), // 1 – ACCESO
|
||
MonitoreoAlarmaPage(), // 2 – ALARMAS
|
||
PerfilUsuarioPage(), // 3 – PERFIL
|
||
];
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_index = 0;
|
||
_navSelected = widget.initialIndex;
|
||
}
|
||
|
||
void _onNavTap(int navIdx) {
|
||
// navIdx: 0=INICIO 1=ACCESO 2=ALARMAS 3=PERFIL
|
||
int pageIdx;
|
||
switch (navIdx) {
|
||
case 0: pageIdx = 0; break; // INICIO → InicioPage
|
||
case 1: pageIdx = 1; break; // ACCESO → ControlAccesoPage
|
||
case 2: pageIdx = 2; break; // ALARMAS → MonitoreoAlarmaPage
|
||
case 3: pageIdx = 3; break; // PERFIL → PerfilUsuarioPage
|
||
default: pageIdx = 0;
|
||
}
|
||
setState(() {
|
||
_index = pageIdx;
|
||
_navSelected = navIdx;
|
||
});
|
||
}
|
||
|
||
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: IndexedStack(index: _index, children: _pages),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
bottomNavigationBar: _bottomNav(),
|
||
);
|
||
}
|
||
|
||
// ── Header compartido ──────────────────────────────────────────────────────
|
||
Widget _header() => Container(
|
||
height: 64,
|
||
color: AppColors.surfaceLow,
|
||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
// Logo + nombre
|
||
Row(children: [
|
||
const Icon(Icons.security, color: AppColors.primary, size: 22),
|
||
const SizedBox(width: 12),
|
||
Text('SENTINEL ONE',
|
||
style: appHeadline(
|
||
size: 18,
|
||
weight: FontWeight.w900,
|
||
color: AppColors.primary,
|
||
spacing: 2.5)),
|
||
]),
|
||
// Sección activa + botón de configuración
|
||
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)),
|
||
]),
|
||
),
|
||
);
|
||
}
|
||
}
|