- 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>
192 lines
6.6 KiB
Dart
192 lines
6.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../theme.dart';
|
|
import '../db/dao/sesiones_dao.dart';
|
|
import '../models/sesion.dart';
|
|
|
|
class HistorialSesionesPage extends StatefulWidget {
|
|
const HistorialSesionesPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<HistorialSesionesPage> createState() => _HistorialSesionesPageState();
|
|
}
|
|
|
|
class _HistorialSesionesPageState extends State<HistorialSesionesPage> {
|
|
final _dao = SesionesDao();
|
|
List<Sesion> _sesiones = [];
|
|
bool _cargando = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_cargar();
|
|
}
|
|
|
|
Future<void> _cargar() async {
|
|
try {
|
|
final data = await _dao.getByUsuario(1);
|
|
if (mounted) setState(() { _sesiones = data; _cargando = false; });
|
|
} catch (_) {
|
|
if (mounted) setState(() => _cargando = false);
|
|
}
|
|
}
|
|
|
|
String _formatFecha(String iso) {
|
|
final dt = DateTime.tryParse(iso)?.toLocal();
|
|
if (dt == null) return iso;
|
|
final d = dt.day.toString().padLeft(2, '0');
|
|
final m = dt.month.toString().padLeft(2, '0');
|
|
final h = dt.hour.toString().padLeft(2, '0');
|
|
final min = dt.minute.toString().padLeft(2, '0');
|
|
return '$d/$m/${dt.year} $h:$min';
|
|
}
|
|
|
|
String _duracion(Sesion s) {
|
|
final inicio = DateTime.tryParse(s.timestampInicio);
|
|
if (inicio == null) return '—';
|
|
final fin = s.timestampFin != null
|
|
? DateTime.tryParse(s.timestampFin!) ?? DateTime.now()
|
|
: DateTime.now();
|
|
final diff = fin.difference(inicio);
|
|
final h = diff.inHours;
|
|
final m = diff.inMinutes.remainder(60);
|
|
if (h > 0) return '${h}h ${m}m';
|
|
return '${m}m';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.surfaceLowest,
|
|
appBar: AppBar(
|
|
backgroundColor: AppColors.surfaceLow,
|
|
elevation: 0,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios_new,
|
|
color: AppColors.onSurface, size: 18),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
title: Text('HISTORIAL DE SESIONES',
|
|
style: appHeadline(size: 15, weight: FontWeight.w800,
|
|
color: AppColors.primary, spacing: 1.5)),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh, color: AppColors.onSurfaceVariant, size: 20),
|
|
onPressed: () { setState(() => _cargando = true); _cargar(); },
|
|
),
|
|
],
|
|
),
|
|
body: _cargando
|
|
? const Center(child: CircularProgressIndicator(color: AppColors.primary))
|
|
: _sesiones.isEmpty
|
|
? _estadoVacio()
|
|
: RefreshIndicator(
|
|
onRefresh: _cargar,
|
|
color: AppColors.primary,
|
|
child: ListView.separated(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _sesiones.length,
|
|
separatorBuilder: (_, __) => const SizedBox(height: 10),
|
|
itemBuilder: (_, i) => _tarjetaSesion(_sesiones[i], i == 0),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _tarjetaSesion(Sesion s, bool esPrimera) {
|
|
final activa = s.activa;
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceHigh,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: activa
|
|
? Border.all(color: AppColors.primary.withOpacity(0.4), width: 1)
|
|
: null,
|
|
),
|
|
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
// Ícono
|
|
Container(
|
|
width: 40, height: 40,
|
|
decoration: BoxDecoration(
|
|
color: activa
|
|
? AppColors.primaryContainer
|
|
: AppColors.surfaceHighest,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Icon(
|
|
activa ? Icons.lock_open : Icons.lock_outline,
|
|
color: activa ? AppColors.primary : AppColors.onSurfaceVariant,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: 14),
|
|
|
|
// Datos
|
|
Expanded(child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(children: [
|
|
Expanded(
|
|
child: Text(_formatFecha(s.timestampInicio),
|
|
style: appHeadline(size: 13, weight: FontWeight.w700)),
|
|
),
|
|
if (activa)
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primaryContainer,
|
|
borderRadius: BorderRadius.circular(99),
|
|
),
|
|
child: Text('ACTIVA',
|
|
style: appLabel(size: 9, weight: FontWeight.bold,
|
|
color: AppColors.primary, spacing: 1.0)),
|
|
),
|
|
]),
|
|
const SizedBox(height: 6),
|
|
|
|
// Fin
|
|
Row(children: [
|
|
const Icon(Icons.logout, size: 12, color: AppColors.onSurfaceVariant),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
activa ? 'Sesión en curso' : _formatFecha(s.timestampFin!),
|
|
style: appLabel(size: 12, color: AppColors.onSurfaceVariant),
|
|
),
|
|
]),
|
|
const SizedBox(height: 4),
|
|
|
|
// Duración y dispositivo
|
|
Row(children: [
|
|
const Icon(Icons.timer_outlined, size: 12, color: AppColors.outline),
|
|
const SizedBox(width: 4),
|
|
Text('Duración: ${_duracion(s)}',
|
|
style: appLabel(size: 11, color: AppColors.outline)),
|
|
if (s.dispositivo != null) ...[
|
|
const SizedBox(width: 12),
|
|
const Icon(Icons.devices, size: 12, color: AppColors.outline),
|
|
const SizedBox(width: 4),
|
|
Text(s.dispositivo!,
|
|
style: appLabel(size: 11, color: AppColors.outline)),
|
|
],
|
|
]),
|
|
],
|
|
)),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _estadoVacio() => Center(
|
|
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
|
const Icon(Icons.history, size: 56, color: AppColors.outlineVariant),
|
|
const SizedBox(height: 16),
|
|
Text('Sin historial de sesiones',
|
|
style: appHeadline(size: 16, color: AppColors.onSurfaceVariant)),
|
|
const SizedBox(height: 8),
|
|
Text('Las sesiones aparecerán aquí después del primer login',
|
|
style: appLabel(size: 13, color: AppColors.outline),
|
|
textAlign: TextAlign.center),
|
|
]),
|
|
);
|
|
}
|