feat: add main layout with bottom navigation and shared header
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>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d28f41f3dd
commit
ff5844b6d9
@@ -0,0 +1,173 @@
|
|||||||
|
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)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import '../theme.dart';
|
||||||
|
import '../pages/settings_page.dart';
|
||||||
|
|
||||||
|
class AppMenuButton extends StatelessWidget {
|
||||||
|
const AppMenuButton({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PopupMenuButton<_MenuItem>(
|
||||||
|
color: AppColors.surfaceHigh,
|
||||||
|
elevation: 8,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
offset: const Offset(0, 48),
|
||||||
|
icon: Container(
|
||||||
|
padding: const EdgeInsets.all(6),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.surfaceHighest,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.more_vert,
|
||||||
|
color: AppColors.primary, size: 20),
|
||||||
|
),
|
||||||
|
itemBuilder: (_) => [
|
||||||
|
_item(Icons.tune, 'Configuración', _MenuItem.configuracion),
|
||||||
|
_item(Icons.sync, 'Sincronización', _MenuItem.sincronizacion),
|
||||||
|
_divider(),
|
||||||
|
_item(Icons.description_outlined, 'Términos y condiciones', _MenuItem.terminos),
|
||||||
|
_item(Icons.privacy_tip_outlined, 'Políticas de privacidad',_MenuItem.privacidad),
|
||||||
|
],
|
||||||
|
onSelected: (value) => _onSelected(context, value),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSelected(BuildContext context, _MenuItem value) {
|
||||||
|
switch (value) {
|
||||||
|
case _MenuItem.configuracion:
|
||||||
|
Navigator.push(context,
|
||||||
|
MaterialPageRoute(builder: (_) => const SettingsPage()));
|
||||||
|
break;
|
||||||
|
case _MenuItem.sincronizacion:
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Row(children: [
|
||||||
|
const Icon(Icons.sync, color: AppColors.primary, size: 18),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Text('Sincronizando datos del sistema...',
|
||||||
|
style: appLabel(size: 13, color: AppColors.onSurface)),
|
||||||
|
]),
|
||||||
|
backgroundColor: AppColors.surfaceHigh,
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case _MenuItem.terminos:
|
||||||
|
_mostrarDialog(context,
|
||||||
|
titulo: 'Términos y Condiciones',
|
||||||
|
icono: Icons.description_outlined,
|
||||||
|
contenido:
|
||||||
|
'El uso de SENTINEL ONE está sujeto a los términos de servicio '
|
||||||
|
'vigentes. El sistema es de uso exclusivo para personal autorizado. '
|
||||||
|
'Cualquier acceso no autorizado será registrado y reportado a las '
|
||||||
|
'autoridades competentes.\n\n'
|
||||||
|
'Versión 2.1 · Vigente desde 01/01/2025',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case _MenuItem.privacidad:
|
||||||
|
_mostrarDialog(context,
|
||||||
|
titulo: 'Políticas de Privacidad',
|
||||||
|
icono: Icons.privacy_tip_outlined,
|
||||||
|
contenido:
|
||||||
|
'SENTINEL ONE recopila y almacena únicamente los datos necesarios '
|
||||||
|
'para el funcionamiento del sistema de seguridad: registros de acceso, '
|
||||||
|
'eventos de alarma e imágenes de cámara.\n\n'
|
||||||
|
'Los datos se conservan por un período de 90 días y son accesibles '
|
||||||
|
'solo para personal con nivel de acceso 3 o superior.\n\n'
|
||||||
|
'Versión 1.4 · Vigente desde 01/03/2025',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mostrarDialog(BuildContext context,
|
||||||
|
{required String titulo,
|
||||||
|
required IconData icono,
|
||||||
|
required String contenido}) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => AlertDialog(
|
||||||
|
backgroundColor: AppColors.surfaceHigh,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
|
title: Row(children: [
|
||||||
|
Icon(icono, color: AppColors.primary, size: 20),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Text(titulo,
|
||||||
|
style: appHeadline(size: 15, weight: FontWeight.bold)),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
content: Text(contenido,
|
||||||
|
style: appLabel(size: 13, color: AppColors.onSurfaceVariant)),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text('Cerrar',
|
||||||
|
style: appLabel(size: 13,
|
||||||
|
weight: FontWeight.bold, color: AppColors.primary)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
PopupMenuItem<_MenuItem> _item(
|
||||||
|
IconData icon, String label, _MenuItem value) =>
|
||||||
|
PopupMenuItem<_MenuItem>(
|
||||||
|
value: value,
|
||||||
|
height: 44,
|
||||||
|
child: Row(children: [
|
||||||
|
Icon(icon, color: AppColors.primary, size: 18),
|
||||||
|
const SizedBox(width: 14),
|
||||||
|
Text(label,
|
||||||
|
style: appLabel(
|
||||||
|
size: 13, color: AppColors.onSurface)),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
PopupMenuEntry<_MenuItem> _divider() =>
|
||||||
|
const PopupMenuDivider(height: 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum _MenuItem { configuracion, sincronizacion, terminos, privacidad }
|
||||||
Reference in New Issue
Block a user