feat: perfil BD, historial sesiones, UX login y config Android
- Perfil conectado a BD: nombre real, edición con iniciales auto - Historial de sesiones: nueva página con duración y badge activa - Ayuda y soporte navega a MensajeriaPage - InicioPage: nombre real desde BD, click avatar → tab perfil - Login: foco automático, Enter = ingresar, click card = foco - ApplicationId: net.siaxsystem.sentinelone en todos los manifests - Linux: libsqlite3-dev requerido en CMakeLists, error amigable en app - BD ruta Linux corregida a ~/.local/share/sentinel_one/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1184ab5fe2
commit
3e2294faf6
@@ -1,22 +1,138 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../theme.dart';
|
||||
import '../models/usuario.dart';
|
||||
import '../db/dao/usuarios_dao.dart';
|
||||
import '../main.dart' show LoginPage;
|
||||
import 'settings_page.dart';
|
||||
import 'seguridad_page.dart';
|
||||
import 'mensageria_page.dart';
|
||||
import 'historial_sesiones_page.dart';
|
||||
|
||||
class PerfilUsuarioPage extends StatelessWidget {
|
||||
class PerfilUsuarioPage extends StatefulWidget {
|
||||
const PerfilUsuarioPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PerfilUsuarioPage> createState() => _PerfilUsuarioPageState();
|
||||
}
|
||||
|
||||
class _PerfilUsuarioPageState extends State<PerfilUsuarioPage> {
|
||||
final _dao = UsuariosDao();
|
||||
Usuario? _usuario;
|
||||
bool _cargando = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cargar();
|
||||
}
|
||||
|
||||
Future<void> _cargar() async {
|
||||
try {
|
||||
final u = await _dao.getById(1);
|
||||
if (mounted) setState(() { _usuario = u; _cargando = false; });
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _cargando = false);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Calcular iniciales desde el nombre ────────────────────────────────────
|
||||
String _calcularIniciales(String nombre) {
|
||||
final partes = nombre.trim().split(RegExp(r'\s+'));
|
||||
if (partes.length == 1) return partes[0][0].toUpperCase();
|
||||
return (partes.first[0] + partes.last[0]).toUpperCase();
|
||||
}
|
||||
|
||||
// ── Editar nombre ─────────────────────────────────────────────────────────
|
||||
Future<void> _editarNombre() async {
|
||||
if (_usuario == null) return;
|
||||
final ctrl = TextEditingController(text: _usuario!.nombre);
|
||||
|
||||
final nuevoNombre = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Editar nombre',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700)),
|
||||
content: TextField(
|
||||
controller: ctrl,
|
||||
autofocus: true,
|
||||
style: appHeadline(size: 14),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Nombre completo',
|
||||
hintStyle: appLabel(size: 13, color: AppColors.outline),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: AppColors.outlineVariant),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: const BorderSide(color: AppColors.primary, width: 2),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceHighest,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 14, vertical: 12),
|
||||
),
|
||||
textCapitalization: TextCapitalization.words,
|
||||
onSubmitted: (v) => Navigator.pop(context, v.trim()),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(size: 13,
|
||||
color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, ctrl.text.trim()),
|
||||
child: Text('Guardar',
|
||||
style: appLabel(size: 13,
|
||||
weight: FontWeight.bold, color: AppColors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
ctrl.dispose();
|
||||
if (nuevoNombre == null || nuevoNombre.isEmpty) return;
|
||||
|
||||
final actualizado = Usuario(
|
||||
id: _usuario!.id,
|
||||
nombre: nuevoNombre,
|
||||
iniciales: _calcularIniciales(nuevoNombre),
|
||||
nivelAcceso: _usuario!.nivelAcceso,
|
||||
pinHash: _usuario!.pinHash,
|
||||
areas: _usuario!.areas,
|
||||
fechaInicio: _usuario!.fechaInicio,
|
||||
fechaFin: _usuario!.fechaFin,
|
||||
activo: _usuario!.activo,
|
||||
sincronizado: false, // marcar para sincronizar
|
||||
);
|
||||
|
||||
await _dao.update(actualizado);
|
||||
if (mounted) setState(() => _usuario = actualizado);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_cargando) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary));
|
||||
}
|
||||
|
||||
final nombre = _usuario?.nombre ?? 'Sin nombre';
|
||||
final iniciales = _usuario?.iniciales ?? '?';
|
||||
final nivel = _usuario?.nivelAcceso ?? 1;
|
||||
final nivelLabel = nivel >= 3 ? 'ACCESO TOTAL' : 'ACCESO NIVEL $nivel';
|
||||
|
||||
return SingleChildScrollView(
|
||||
primary: false,
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_avatarCard(context),
|
||||
_avatarCard(nombre, iniciales, nivel, nivelLabel),
|
||||
const SizedBox(height: 24),
|
||||
_statsGrid(),
|
||||
const SizedBox(height: 32),
|
||||
@@ -28,8 +144,10 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// ── Avatar + info ───────────────────────────────────────────────────────────
|
||||
Widget _avatarCard(BuildContext context) => Container(
|
||||
// ── Avatar + info ──────────────────────────────────────────────────────────
|
||||
Widget _avatarCard(String nombre, String iniciales, int nivel,
|
||||
String nivelLabel) =>
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
@@ -46,53 +164,54 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20, spreadRadius: 2,
|
||||
)
|
||||
],
|
||||
boxShadow: [BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20, spreadRadius: 2,
|
||||
)],
|
||||
),
|
||||
child: Center(
|
||||
child: Text('JD',
|
||||
style: appHeadline(
|
||||
size: 28, weight: FontWeight.w800,
|
||||
child: Text(iniciales,
|
||||
style: appHeadline(size: 28, weight: FontWeight.w800,
|
||||
color: AppColors.primaryContainer)),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0, right: 0,
|
||||
child: Container(
|
||||
width: 24, height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceHighest,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: AppColors.surfaceHigh, width: 2),
|
||||
child: GestureDetector(
|
||||
onTap: _editarNombre,
|
||||
child: Container(
|
||||
width: 24, height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceHighest,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.surfaceHigh, width: 2),
|
||||
),
|
||||
child: const Icon(Icons.edit,
|
||||
size: 13, color: AppColors.primary),
|
||||
),
|
||||
child: const Icon(Icons.edit, size: 13, color: AppColors.primary),
|
||||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 16),
|
||||
Text('Juan Díaz',
|
||||
Text(nombre,
|
||||
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
||||
const SizedBox(height: 4),
|
||||
Text('Operador de Seguridad',
|
||||
style: appLabel(size: 13)),
|
||||
Text('Operador de Seguridad', style: appLabel(size: 13)),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(99)),
|
||||
child: Text('NIVEL 3 · ACCESO TOTAL',
|
||||
child: Text('NIVEL $nivel · $nivelLabel',
|
||||
style: appLabel(size: 10, weight: FontWeight.bold,
|
||||
color: AppColors.primary, spacing: 1.5)),
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
// ── Estadísticas ────────────────────────────────────────────────────────────
|
||||
// ── Estadísticas ───────────────────────────────────────────────────────────
|
||||
Widget _statsGrid() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -128,7 +247,7 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
]),
|
||||
);
|
||||
|
||||
// ── Opciones ────────────────────────────────────────────────────────────────
|
||||
// ── Opciones ───────────────────────────────────────────────────────────────
|
||||
Widget _seccionOpciones(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -149,10 +268,17 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
}),
|
||||
const Divider(color: AppColors.outlineVariant, height: 1),
|
||||
_opcionItem(Icons.history, 'Historial de sesiones',
|
||||
'Últimos accesos al sistema', () {}),
|
||||
'Últimos accesos al sistema', () {
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const HistorialSesionesPage()));
|
||||
}),
|
||||
const Divider(color: AppColors.outlineVariant, height: 1),
|
||||
_opcionItem(Icons.help_outline, 'Ayuda y soporte',
|
||||
'Manual del operador', () {}),
|
||||
'Contactar con soporte técnico', () {
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (_) => const MensajeriaPage()));
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -186,7 +312,7 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
|
||||
// ── Cerrar sesión ───────────────────────────────────────────────────────────
|
||||
// ── Cerrar sesión ──────────────────────────────────────────────────────────
|
||||
Widget _botonCerrarSesion(BuildContext context) => SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
@@ -217,7 +343,8 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(size: 13, color: AppColors.onSurfaceVariant)),
|
||||
style: appLabel(size: 13,
|
||||
color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
@@ -231,7 +358,6 @@ class PerfilUsuarioPage extends StatelessWidget {
|
||||
|
||||
if (confirmar != true) return;
|
||||
|
||||
// Limpia el flag de auto-login si se implementa en el futuro
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove('autologin');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user