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
@@ -0,0 +1,191 @@
|
||||
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),
|
||||
]),
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/usuarios_dao.dart';
|
||||
import 'mensageria_page.dart';
|
||||
|
||||
// ─── Datos del banner ─────────────────────────────────────────────────────────
|
||||
@@ -106,7 +107,8 @@ const _eventos = [
|
||||
|
||||
// ─── Página ───────────────────────────────────────────────────────────────────
|
||||
class InicioPage extends StatefulWidget {
|
||||
const InicioPage({Key? key}) : super(key: key);
|
||||
final VoidCallback? onGoToPerfil;
|
||||
const InicioPage({Key? key, this.onGoToPerfil}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<InicioPage> createState() => _InicioPageState();
|
||||
@@ -118,6 +120,17 @@ class _InicioPageState extends State<InicioPage>
|
||||
final _pageController = PageController();
|
||||
Timer? _bannerTimer;
|
||||
|
||||
String _nombreUsuario = 'Usuario';
|
||||
|
||||
Future<void> _cargarUsuario() async {
|
||||
try {
|
||||
final u = await UsuariosDao().getById(1);
|
||||
if (mounted && u != null) {
|
||||
setState(() => _nombreUsuario = u.nombre);
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
late final AnimationController _panicCtrl;
|
||||
late final Animation<double> _pingScale;
|
||||
late final Animation<double> _pingOpacity;
|
||||
@@ -125,6 +138,7 @@ class _InicioPageState extends State<InicioPage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cargarUsuario();
|
||||
// Auto-avance del banner cada 4 segundos
|
||||
_bannerTimer = Timer.periodic(const Duration(seconds: 4), (_) {
|
||||
final next = (_bannerPage + 1) % _banners.length;
|
||||
@@ -194,14 +208,16 @@ class _InicioPageState extends State<InicioPage>
|
||||
style:
|
||||
appLabel(size: 11, color: AppColors.onSurfaceVariant)),
|
||||
const SizedBox(height: 2),
|
||||
Text('Juan Díaz',
|
||||
Text(_nombreUsuario,
|
||||
style: appHeadline(
|
||||
size: 20,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.onSurface)),
|
||||
]),
|
||||
// Avatar
|
||||
Stack(clipBehavior: Clip.none, children: [
|
||||
// Avatar — click navega al perfil
|
||||
GestureDetector(
|
||||
onTap: widget.onGoToPerfil,
|
||||
child: Stack(clipBehavior: Clip.none, children: [
|
||||
Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
@@ -233,6 +249,7 @@ class _InicioPageState extends State<InicioPage>
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -130,8 +130,15 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
try {
|
||||
// Borra la BD existente
|
||||
if (Platform.isLinux || Platform.isWindows) {
|
||||
final dbPath = p.join(Directory.current.path, 'sentinel_one.db');
|
||||
await databaseFactoryFfi.deleteDatabase(dbPath);
|
||||
final String dbDir;
|
||||
if (Platform.isLinux) {
|
||||
final home = Platform.environment['HOME'] ?? Directory.current.path;
|
||||
dbDir = p.join(home, '.local', 'share', 'sentinel_one');
|
||||
} else {
|
||||
dbDir = Directory.current.path;
|
||||
}
|
||||
await databaseFactoryFfi.deleteDatabase(
|
||||
p.join(dbDir, 'sentinel_one.db'));
|
||||
} else {
|
||||
final dbPath = p.join(await getDatabasesPath(), 'sentinel_one.db');
|
||||
await deleteDatabase(dbPath);
|
||||
@@ -147,12 +154,73 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
_snack('Base de datos inicializada correctamente', esError: false);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
_snack('Error al inicializar: $e');
|
||||
final msg = e.toString();
|
||||
if (msg.contains('libsqlite3.so')) {
|
||||
_mostrarErrorSqlite();
|
||||
} else {
|
||||
_snack('Error al inicializar: $e');
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _iniciandoBd = false);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Error libsqlite3.so ────────────────────────────────────────────────────
|
||||
void _mostrarErrorSqlite() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Dependencia faltante',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700,
|
||||
color: AppColors.error)),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'La librería SQLite no está instalada en este sistema Linux.',
|
||||
style: appLabel(size: 13),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Abre una terminal y ejecuta:',
|
||||
style: appLabel(size: 12,
|
||||
color: AppColors.onSurfaceVariant)),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLowest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'sudo apt install libsqlite3-dev',
|
||||
style: appLabel(size: 13,
|
||||
color: AppColors.primary,
|
||||
weight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text('Luego reinicia la aplicación.',
|
||||
style: appLabel(size: 12,
|
||||
color: AppColors.onSurfaceVariant)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Entendido',
|
||||
style: appLabel(size: 13,
|
||||
weight: FontWeight.bold,
|
||||
color: AppColors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Sincronización ─────────────────────────────────────────────────────────
|
||||
Future<void> _iniciarSincronizacion() async {
|
||||
setState(() => _sincronizando = true);
|
||||
|
||||
Reference in New Issue
Block a user