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
@@ -101,12 +101,30 @@ secondary #B4CAD6 // Azul grisáceo
|
|||||||
|
|
||||||
## Instalación y ejecución
|
## Instalación y ejecución
|
||||||
|
|
||||||
|
### Plataformas soportadas
|
||||||
|
|
||||||
|
| Plataforma | Estado |
|
||||||
|
|------------|--------|
|
||||||
|
| Android | ✅ Target principal |
|
||||||
|
| iOS | ✅ Target principal |
|
||||||
|
| Linux (Ubuntu Touch) | ✅ Soportado |
|
||||||
|
|
||||||
### Requisitos
|
### Requisitos
|
||||||
|
|
||||||
- Flutter SDK `>=2.17.0`
|
- Flutter SDK `>=2.17.0`
|
||||||
- Dart SDK `>=2.17.0`
|
- Dart SDK `>=2.17.0`
|
||||||
- Android Studio / VS Code con extensión Flutter
|
- Android Studio / VS Code con extensión Flutter
|
||||||
- Dispositivo físico o emulador Android/iOS
|
- Dispositivo físico o emulador Android / iOS / Ubuntu Touch
|
||||||
|
|
||||||
|
### Requisitos adicionales — Linux / Ubuntu Touch
|
||||||
|
|
||||||
|
Antes de compilar o ejecutar en Linux, instalar la librería SQLite:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install libsqlite3-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
> Sin este paquete la app arranca pero falla al intentar inicializar la base de datos local. La app mostrará un diálogo con esta instrucción si detecta el error en runtime.
|
||||||
|
|
||||||
### Pasos
|
### Pasos
|
||||||
|
|
||||||
@@ -115,14 +133,23 @@ secondary #B4CAD6 // Azul grisáceo
|
|||||||
git clone <url-del-repositorio>
|
git clone <url-del-repositorio>
|
||||||
cd seguridad_electronica
|
cd seguridad_electronica
|
||||||
|
|
||||||
# 2. Instalar dependencias
|
# 2. (Solo Linux) Instalar dependencia SQLite
|
||||||
|
sudo apt install libsqlite3-dev
|
||||||
|
|
||||||
|
# 3. Instalar dependencias Flutter
|
||||||
flutter pub get
|
flutter pub get
|
||||||
|
|
||||||
# 3. Ejecutar en modo debug
|
# 4. Ejecutar en modo debug
|
||||||
flutter run
|
flutter run
|
||||||
|
|
||||||
# 4. Compilar APK de release
|
# 5. Compilar para Android
|
||||||
flutter build apk --release
|
flutter build apk --release
|
||||||
|
|
||||||
|
# 6. Compilar para iOS
|
||||||
|
flutter build ios --release
|
||||||
|
|
||||||
|
# 7. Compilar para Linux
|
||||||
|
flutter build linux --release
|
||||||
```
|
```
|
||||||
|
|
||||||
### Credenciales de prueba
|
### Credenciales de prueba
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId "com.example.seguridad_electronica"
|
applicationId "net.siaxsystem.sentinelone"
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion flutter.minSdkVersion
|
||||||
targetSdkVersion flutter.targetSdkVersion
|
targetSdkVersion flutter.targetSdkVersion
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.seguridad_electronica">
|
package="net.siaxsystem.sentinelone">
|
||||||
<!-- Flutter needs it to communicate with the running application
|
<!-- Flutter needs it to communicate with the running application
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.seguridad_electronica">
|
package="net.siaxsystem.sentinelone">
|
||||||
<application
|
<application
|
||||||
android:label="seguridad_electronica"
|
android:label="seguridad_electronica"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.siaxsystem.sentinelone
|
||||||
|
|
||||||
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
|
class MainActivity: FlutterActivity() {
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.seguridad_electronica">
|
package="net.siaxsystem.sentinelone">
|
||||||
<!-- Flutter needs it to communicate with the running application
|
<!-- Flutter needs it to communicate with the running application
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
|
|||||||
+24
-8
@@ -50,6 +50,14 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
|
|
||||||
bool _cargando = false;
|
bool _cargando = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
||||||
|
_focusNodes[0].requestFocus();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
for (final c in _controllers) c.dispose();
|
for (final c in _controllers) c.dispose();
|
||||||
@@ -65,13 +73,17 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onKeyEvent(int index, RawKeyEvent event) {
|
void _onKeyEvent(int index, RawKeyEvent event) {
|
||||||
if (event is RawKeyDownEvent &&
|
if (event is! RawKeyDownEvent) return;
|
||||||
event.logicalKey == LogicalKeyboardKey.backspace &&
|
if (event.logicalKey == LogicalKeyboardKey.backspace &&
|
||||||
_controllers[index].text.isEmpty &&
|
_controllers[index].text.isEmpty &&
|
||||||
index > 0) {
|
index > 0) {
|
||||||
_focusNodes[index - 1].requestFocus();
|
_focusNodes[index - 1].requestFocus();
|
||||||
_controllers[index - 1].clear();
|
_controllers[index - 1].clear();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
} else if (event.logicalKey == LogicalKeyboardKey.enter ||
|
||||||
|
event.logicalKey == LogicalKeyboardKey.numpadEnter) {
|
||||||
|
final filled = _controllers.where((c) => c.text.isNotEmpty).length;
|
||||||
|
if (filled >= 4 && !_cargando) _handleLogin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +152,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
elevation: 0,
|
elevation: 0,
|
||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
title: Row(children: [
|
title: Row(children: [
|
||||||
const Icon(Icons.security, color: AppColors.primary, size: 20),
|
Image.asset('lib/recursos/logo_app.png', width: 28, height: 28),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Text('SENTINEL ONE',
|
Text('SENTINEL ONE',
|
||||||
style: appHeadline(size: 16, weight: FontWeight.w900,
|
style: appHeadline(size: 16, weight: FontWeight.w900,
|
||||||
@@ -162,16 +174,17 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
// Logo
|
// Logo
|
||||||
Container(
|
Container(
|
||||||
width: 72, height: 72,
|
width: 96, height: 96,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: AppColors.primaryContainer,
|
|
||||||
boxShadow: [BoxShadow(
|
boxShadow: [BoxShadow(
|
||||||
color: AppColors.primary.withOpacity(0.3),
|
color: AppColors.primary.withOpacity(0.3),
|
||||||
blurRadius: 24, spreadRadius: 4)],
|
blurRadius: 24, spreadRadius: 4)],
|
||||||
),
|
),
|
||||||
child: const Icon(Icons.security,
|
child: ClipOval(
|
||||||
size: 36, color: AppColors.primary),
|
child: Image.asset('lib/recursos/logo_app.png',
|
||||||
|
fit: BoxFit.cover),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text('SENTINEL ONE',
|
Text('SENTINEL ONE',
|
||||||
@@ -187,7 +200,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
color: AppColors.onSurfaceVariant)),
|
color: AppColors.onSurfaceVariant)),
|
||||||
const SizedBox(height: 48),
|
const SizedBox(height: 48),
|
||||||
// Código de acceso
|
// Código de acceso
|
||||||
Container(
|
GestureDetector(
|
||||||
|
onTap: () => _focusNodes[0].requestFocus(),
|
||||||
|
child: Container(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: AppColors.surfaceHigh,
|
color: AppColors.surfaceHigh,
|
||||||
@@ -211,6 +226,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
fontSize: 11,
|
fontSize: 11,
|
||||||
color: AppColors.outline)),
|
color: AppColors.outline)),
|
||||||
]),
|
]),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
|
|||||||
+35
-33
@@ -15,39 +15,39 @@ class MainPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MainPageState extends State<MainPage> {
|
class _MainPageState extends State<MainPage> {
|
||||||
late int _index;
|
late final PageController _pageController;
|
||||||
// Guardamos también qué ítem del nav está "seleccionado visualmente"
|
int _navSelected = 0;
|
||||||
// (INICIO y ALARMAS apuntan al mismo índice del stack)
|
|
||||||
late int _navSelected;
|
|
||||||
|
|
||||||
static const _pages = [
|
List<Widget> get _pages => [
|
||||||
InicioPage(), // 0 – INICIO
|
InicioPage(onGoToPerfil: () => _onNavTap(3)),
|
||||||
ControlAccesoPage(), // 1 – ACCESO
|
const ControlAccesoPage(),
|
||||||
MonitoreoAlarmaPage(), // 2 – ALARMAS
|
const MonitoreoAlarmaPage(),
|
||||||
PerfilUsuarioPage(), // 3 – PERFIL
|
const PerfilUsuarioPage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_index = 0;
|
|
||||||
_navSelected = widget.initialIndex;
|
_navSelected = widget.initialIndex;
|
||||||
|
_pageController = PageController(initialPage: widget.initialIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onNavTap(int navIdx) {
|
@override
|
||||||
// navIdx: 0=INICIO 1=ACCESO 2=ALARMAS 3=PERFIL
|
void dispose() {
|
||||||
int pageIdx;
|
_pageController.dispose();
|
||||||
switch (navIdx) {
|
super.dispose();
|
||||||
case 0: pageIdx = 0; break; // INICIO → InicioPage
|
}
|
||||||
case 1: pageIdx = 1; break; // ACCESO → ControlAccesoPage
|
|
||||||
case 2: pageIdx = 2; break; // ALARMAS → MonitoreoAlarmaPage
|
void _onNavTap(int idx) {
|
||||||
case 3: pageIdx = 3; break; // PERFIL → PerfilUsuarioPage
|
_pageController.animateToPage(
|
||||||
default: pageIdx = 0;
|
idx,
|
||||||
}
|
duration: const Duration(milliseconds: 300),
|
||||||
setState(() {
|
curve: Curves.easeInOut,
|
||||||
_index = pageIdx;
|
);
|
||||||
_navSelected = navIdx;
|
}
|
||||||
});
|
|
||||||
|
void _onPageChanged(int idx) {
|
||||||
|
setState(() => _navSelected = idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
String get _tituloActual {
|
String get _tituloActual {
|
||||||
@@ -70,7 +70,12 @@ class _MainPageState extends State<MainPage> {
|
|||||||
children: [
|
children: [
|
||||||
_header(),
|
_header(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: IndexedStack(index: _index, children: _pages),
|
child: PageView(
|
||||||
|
controller: _pageController,
|
||||||
|
onPageChanged: _onPageChanged,
|
||||||
|
children: _pages,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -87,9 +92,8 @@ class _MainPageState extends State<MainPage> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
// Logo + nombre
|
|
||||||
Row(children: [
|
Row(children: [
|
||||||
const Icon(Icons.security, color: AppColors.primary, size: 22),
|
Image.asset('lib/recursos/logo_app.png', width: 30, height: 30),
|
||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Text('SENTINEL ONE',
|
Text('SENTINEL ONE',
|
||||||
style: appHeadline(
|
style: appHeadline(
|
||||||
@@ -98,7 +102,6 @@ class _MainPageState extends State<MainPage> {
|
|||||||
color: AppColors.primary,
|
color: AppColors.primary,
|
||||||
spacing: 2.5)),
|
spacing: 2.5)),
|
||||||
]),
|
]),
|
||||||
// Sección activa + botón de configuración
|
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Text(_tituloActual,
|
Text(_tituloActual,
|
||||||
style: appLabel(
|
style: appLabel(
|
||||||
@@ -130,17 +133,16 @@ class _MainPageState extends State<MainPage> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
_navItem(Icons.home_outlined, 'INICIO', 0),
|
_navItem(Icons.home_outlined, 'INICIO', 0),
|
||||||
_navItem(Icons.lock_open, 'ACCESO', 1),
|
_navItem(Icons.lock_open, 'ACCESO', 1),
|
||||||
_navItem(Icons.notifications_active, 'ALARMAS', 2),
|
_navItem(Icons.notifications_active, 'ALARMAS', 2),
|
||||||
_navItem(Icons.person_outline, 'PERFIL', 3),
|
_navItem(Icons.person_outline, 'PERFIL', 3),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Widget _navItem(IconData icon, String label, int idx) {
|
Widget _navItem(IconData icon, String label, int idx) {
|
||||||
final isActive = _navSelected == idx;
|
final isActive = _navSelected == idx;
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => _onNavTap(idx),
|
onTap: () => _onNavTap(idx),
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
|
|||||||
@@ -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 'dart:async';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../theme.dart';
|
import '../theme.dart';
|
||||||
|
import '../db/dao/usuarios_dao.dart';
|
||||||
import 'mensageria_page.dart';
|
import 'mensageria_page.dart';
|
||||||
|
|
||||||
// ─── Datos del banner ─────────────────────────────────────────────────────────
|
// ─── Datos del banner ─────────────────────────────────────────────────────────
|
||||||
@@ -106,7 +107,8 @@ const _eventos = [
|
|||||||
|
|
||||||
// ─── Página ───────────────────────────────────────────────────────────────────
|
// ─── Página ───────────────────────────────────────────────────────────────────
|
||||||
class InicioPage extends StatefulWidget {
|
class InicioPage extends StatefulWidget {
|
||||||
const InicioPage({Key? key}) : super(key: key);
|
final VoidCallback? onGoToPerfil;
|
||||||
|
const InicioPage({Key? key, this.onGoToPerfil}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<InicioPage> createState() => _InicioPageState();
|
State<InicioPage> createState() => _InicioPageState();
|
||||||
@@ -118,6 +120,17 @@ class _InicioPageState extends State<InicioPage>
|
|||||||
final _pageController = PageController();
|
final _pageController = PageController();
|
||||||
Timer? _bannerTimer;
|
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 AnimationController _panicCtrl;
|
||||||
late final Animation<double> _pingScale;
|
late final Animation<double> _pingScale;
|
||||||
late final Animation<double> _pingOpacity;
|
late final Animation<double> _pingOpacity;
|
||||||
@@ -125,6 +138,7 @@ class _InicioPageState extends State<InicioPage>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_cargarUsuario();
|
||||||
// Auto-avance del banner cada 4 segundos
|
// Auto-avance del banner cada 4 segundos
|
||||||
_bannerTimer = Timer.periodic(const Duration(seconds: 4), (_) {
|
_bannerTimer = Timer.periodic(const Duration(seconds: 4), (_) {
|
||||||
final next = (_bannerPage + 1) % _banners.length;
|
final next = (_bannerPage + 1) % _banners.length;
|
||||||
@@ -194,14 +208,16 @@ class _InicioPageState extends State<InicioPage>
|
|||||||
style:
|
style:
|
||||||
appLabel(size: 11, color: AppColors.onSurfaceVariant)),
|
appLabel(size: 11, color: AppColors.onSurfaceVariant)),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
Text('Juan Díaz',
|
Text(_nombreUsuario,
|
||||||
style: appHeadline(
|
style: appHeadline(
|
||||||
size: 20,
|
size: 20,
|
||||||
weight: FontWeight.w800,
|
weight: FontWeight.w800,
|
||||||
color: AppColors.onSurface)),
|
color: AppColors.onSurface)),
|
||||||
]),
|
]),
|
||||||
// Avatar
|
// Avatar — click navega al perfil
|
||||||
Stack(clipBehavior: Clip.none, children: [
|
GestureDetector(
|
||||||
|
onTap: widget.onGoToPerfil,
|
||||||
|
child: Stack(clipBehavior: Clip.none, children: [
|
||||||
Container(
|
Container(
|
||||||
width: 52,
|
width: 52,
|
||||||
height: 52,
|
height: 52,
|
||||||
@@ -233,6 +249,7 @@ class _InicioPageState extends State<InicioPage>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,138 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../theme.dart';
|
import '../theme.dart';
|
||||||
|
import '../models/usuario.dart';
|
||||||
|
import '../db/dao/usuarios_dao.dart';
|
||||||
import '../main.dart' show LoginPage;
|
import '../main.dart' show LoginPage;
|
||||||
import 'settings_page.dart';
|
import 'settings_page.dart';
|
||||||
import 'seguridad_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);
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return SingleChildScrollView(
|
||||||
primary: false,
|
primary: false,
|
||||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_avatarCard(context),
|
_avatarCard(nombre, iniciales, nivel, nivelLabel),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
_statsGrid(),
|
_statsGrid(),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
@@ -28,8 +144,10 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Avatar + info ───────────────────────────────────────────────────────────
|
// ── Avatar + info ──────────────────────────────────────────────────────────
|
||||||
Widget _avatarCard(BuildContext context) => Container(
|
Widget _avatarCard(String nombre, String iniciales, int nivel,
|
||||||
|
String nivelLabel) =>
|
||||||
|
Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -46,53 +164,54 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [BoxShadow(
|
||||||
BoxShadow(
|
color: AppColors.primary.withOpacity(0.3),
|
||||||
color: AppColors.primary.withOpacity(0.3),
|
blurRadius: 20, spreadRadius: 2,
|
||||||
blurRadius: 20, spreadRadius: 2,
|
)],
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text('JD',
|
child: Text(iniciales,
|
||||||
style: appHeadline(
|
style: appHeadline(size: 28, weight: FontWeight.w800,
|
||||||
size: 28, weight: FontWeight.w800,
|
|
||||||
color: AppColors.primaryContainer)),
|
color: AppColors.primaryContainer)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 0, right: 0,
|
bottom: 0, right: 0,
|
||||||
child: Container(
|
child: GestureDetector(
|
||||||
width: 24, height: 24,
|
onTap: _editarNombre,
|
||||||
decoration: BoxDecoration(
|
child: Container(
|
||||||
color: AppColors.surfaceHighest,
|
width: 24, height: 24,
|
||||||
shape: BoxShape.circle,
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: AppColors.surfaceHigh, width: 2),
|
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),
|
const SizedBox(height: 16),
|
||||||
Text('Juan Díaz',
|
Text(nombre,
|
||||||
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text('Operador de Seguridad',
|
Text('Operador de Seguridad', style: appLabel(size: 13)),
|
||||||
style: appLabel(size: 13)),
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: AppColors.primaryContainer,
|
color: AppColors.primaryContainer,
|
||||||
borderRadius: BorderRadius.circular(99)),
|
borderRadius: BorderRadius.circular(99)),
|
||||||
child: Text('NIVEL 3 · ACCESO TOTAL',
|
child: Text('NIVEL $nivel · $nivelLabel',
|
||||||
style: appLabel(size: 10, weight: FontWeight.bold,
|
style: appLabel(size: 10, weight: FontWeight.bold,
|
||||||
color: AppColors.primary, spacing: 1.5)),
|
color: AppColors.primary, spacing: 1.5)),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
// ── Estadísticas ────────────────────────────────────────────────────────────
|
// ── Estadísticas ───────────────────────────────────────────────────────────
|
||||||
Widget _statsGrid() => Column(
|
Widget _statsGrid() => Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -128,7 +247,7 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
// ── Opciones ────────────────────────────────────────────────────────────────
|
// ── Opciones ───────────────────────────────────────────────────────────────
|
||||||
Widget _seccionOpciones(BuildContext context) => Column(
|
Widget _seccionOpciones(BuildContext context) => Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -149,10 +268,17 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
}),
|
}),
|
||||||
const Divider(color: AppColors.outlineVariant, height: 1),
|
const Divider(color: AppColors.outlineVariant, height: 1),
|
||||||
_opcionItem(Icons.history, 'Historial de sesiones',
|
_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),
|
const Divider(color: AppColors.outlineVariant, height: 1),
|
||||||
_opcionItem(Icons.help_outline, 'Ayuda y soporte',
|
_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(
|
Widget _botonCerrarSesion(BuildContext context) => SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
@@ -217,7 +343,8 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context, false),
|
onPressed: () => Navigator.pop(context, false),
|
||||||
child: Text('Cancelar',
|
child: Text('Cancelar',
|
||||||
style: appLabel(size: 13, color: AppColors.onSurfaceVariant)),
|
style: appLabel(size: 13,
|
||||||
|
color: AppColors.onSurfaceVariant)),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context, true),
|
onPressed: () => Navigator.pop(context, true),
|
||||||
@@ -231,7 +358,6 @@ class PerfilUsuarioPage extends StatelessWidget {
|
|||||||
|
|
||||||
if (confirmar != true) return;
|
if (confirmar != true) return;
|
||||||
|
|
||||||
// Limpia el flag de auto-login si se implementa en el futuro
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
await prefs.remove('autologin');
|
await prefs.remove('autologin');
|
||||||
|
|
||||||
|
|||||||
@@ -130,8 +130,15 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
try {
|
try {
|
||||||
// Borra la BD existente
|
// Borra la BD existente
|
||||||
if (Platform.isLinux || Platform.isWindows) {
|
if (Platform.isLinux || Platform.isWindows) {
|
||||||
final dbPath = p.join(Directory.current.path, 'sentinel_one.db');
|
final String dbDir;
|
||||||
await databaseFactoryFfi.deleteDatabase(dbPath);
|
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 {
|
} else {
|
||||||
final dbPath = p.join(await getDatabasesPath(), 'sentinel_one.db');
|
final dbPath = p.join(await getDatabasesPath(), 'sentinel_one.db');
|
||||||
await deleteDatabase(dbPath);
|
await deleteDatabase(dbPath);
|
||||||
@@ -147,12 +154,73 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
_snack('Base de datos inicializada correctamente', esError: false);
|
_snack('Base de datos inicializada correctamente', esError: false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!mounted) return;
|
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 {
|
} finally {
|
||||||
if (mounted) setState(() => _iniciandoBd = false);
|
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 ─────────────────────────────────────────────────────────
|
// ── Sincronización ─────────────────────────────────────────────────────────
|
||||||
Future<void> _iniciarSincronizacion() async {
|
Future<void> _iniciarSincronizacion() async {
|
||||||
setState(() => _sincronizando = true);
|
setState(() => _sincronizando = true);
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})
|
|||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
|
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
|
||||||
|
|
||||||
|
# SQLite3 — requerido por sqflite_common_ffi
|
||||||
|
# Si falla: sudo apt install libsqlite3-dev
|
||||||
|
pkg_check_modules(SQLITE3 REQUIRED sqlite3)
|
||||||
|
|
||||||
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
|
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
|
||||||
|
|
||||||
# Define the application target. To change its name, change BINARY_NAME above,
|
# Define the application target. To change its name, change BINARY_NAME above,
|
||||||
|
|||||||
+51
-6
@@ -1,7 +1,7 @@
|
|||||||
# SENTINEL ONE — Plan del Proyecto
|
# SENTINEL ONE — Plan del Proyecto
|
||||||
**App:** Sistema de Seguridad Electrónica
|
**App:** Sistema de Seguridad Electrónica
|
||||||
**Stack:** Flutter · Google Fonts (Manrope + Inter) · Material 3 · Dark Theme
|
**Stack:** Flutter · Google Fonts (Manrope + Inter) · Material 3 · Dark Theme
|
||||||
**Última revisión:** 2026-04-14 (sesión 3)
|
**Última revisión:** 2026-04-16 (sesión 4)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -15,16 +15,19 @@
|
|||||||
| Monitoreo y Alarmas | `pages/monitoreo_alarma_page.dart` | ✅ Completo |
|
| Monitoreo y Alarmas | `pages/monitoreo_alarma_page.dart` | ✅ Completo |
|
||||||
| Control de Acceso | `pages/control_acceso_page.dart` | 🟡 Parcial |
|
| Control de Acceso | `pages/control_acceso_page.dart` | 🟡 Parcial |
|
||||||
| Mensajería (chat WhatsApp) | `pages/mensageria_page.dart` | ✅ Completo |
|
| Mensajería (chat WhatsApp) | `pages/mensageria_page.dart` | ✅ Completo |
|
||||||
| Perfil de Usuario | `pages/perfil_usuario_page.dart` | ✅ Completo |
|
| Perfil de Usuario | `pages/perfil_usuario_page.dart` | ✅ BD conectada |
|
||||||
| Cambio de PIN | `pages/seguridad_page.dart` | ✅ Completo |
|
| Cambio de PIN | `pages/seguridad_page.dart` | ✅ Completo |
|
||||||
|
| Historial de sesiones | `pages/historial_sesiones_page.dart` | ✅ Completo |
|
||||||
| Registro de usuario | `pages/register_page.dart` | 🔴 Sin estilo del sistema |
|
| Registro de usuario | `pages/register_page.dart` | 🔴 Sin estilo del sistema |
|
||||||
| Configuración | `pages/settings_page.dart` | 🔴 Sin estilo del sistema |
|
| Configuración | `pages/settings_page.dart` | 🟡 Parcial |
|
||||||
| Alarmas (página propia) | `pages/alarmas_page.dart` | 🔴 Vacío |
|
| Alarmas (página propia) | `pages/alarmas_page.dart` | 🔴 Vacío |
|
||||||
|
| Clientes | `pages/clientes_page.dart` | 🔴 Pendiente |
|
||||||
|
| Suscripciones | `pages/suscripciones_page.dart` | 🔴 Pendiente |
|
||||||
| Tema / Colores | `theme.dart` | ✅ Completo |
|
| Tema / Colores | `theme.dart` | ✅ Completo |
|
||||||
| Menú global | `widgets/app_menu_button.dart` | ✅ Completo |
|
| Menú global | `widgets/app_menu_button.dart` | ✅ Completo |
|
||||||
| Base de datos SQLite | `db/database_helper.dart` | ✅ Completo |
|
| Base de datos SQLite | `db/database_helper.dart` | ✅ v2 — 14 tablas |
|
||||||
| Modelos de datos | `models/*.dart` (10 modelos) | ✅ Completo |
|
| Modelos de datos | `models/*.dart` (12 modelos) | ✅ Completo |
|
||||||
| DAOs | `db/dao/*.dart` (12 DAOs) | ✅ Completo |
|
| DAOs | `db/dao/*.dart` (14 DAOs) | ✅ Completo |
|
||||||
| ApiAuthService | `services/api_auth_service.dart` | ✅ Estructura lista |
|
| ApiAuthService | `services/api_auth_service.dart` | ✅ Estructura lista |
|
||||||
| Sincronizador | `services/sincronizador.dart` | ✅ Estructura lista |
|
| Sincronizador | `services/sincronizador.dart` | ✅ Estructura lista |
|
||||||
|
|
||||||
@@ -41,6 +44,9 @@
|
|||||||
- PIN inicial por defecto: `123456` — si no hay hash guardado, se compara contra ese valor
|
- PIN inicial por defecto: `123456` — si no hay hash guardado, se compara contra ese valor
|
||||||
- El login NO depende de SQLite — funciona en todas las plataformas sin plugins nativos
|
- El login NO depende de SQLite — funciona en todas las plataformas sin plugins nativos
|
||||||
- Spinner de carga mientras valida, mensaje de error visible en snackbar
|
- Spinner de carga mientras valida, mensaje de error visible en snackbar
|
||||||
|
- **Foco automático** al primer campo al abrir la página (`initState` + `addPostFrameCallback`)
|
||||||
|
- **Click en el card** mueve el foco al primer input (`GestureDetector` → `requestFocus`)
|
||||||
|
- **Tecla Enter** dispara login si hay 4+ dígitos (manejo en `_onKeyEvent` — Enter y NumpadEnter)
|
||||||
|
|
||||||
### Cambio de PIN (`pages/seguridad_page.dart`)
|
### Cambio de PIN (`pages/seguridad_page.dart`)
|
||||||
- Accesible desde Perfil → Seguridad
|
- Accesible desde Perfil → Seguridad
|
||||||
@@ -385,6 +391,32 @@ lib/
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Plataformas objetivo
|
||||||
|
|
||||||
|
| Plataforma | Notas |
|
||||||
|
|------------|-------|
|
||||||
|
| Android | Target principal — `sqflite` nativo, `getDatabasesPath()` |
|
||||||
|
| iOS | Target principal — `sqflite` nativo, `getDatabasesPath()` |
|
||||||
|
| Linux (Ubuntu Touch) | Mobile Linux — `sqflite_common_ffi`, BD en `~/.local/share/sentinel_one/` |
|
||||||
|
|
||||||
|
> macOS y Windows **no son targets** de este proyecto.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Requisitos del sistema — Linux / Ubuntu Touch
|
||||||
|
|
||||||
|
| Paquete | Comando de instalación | Por qué |
|
||||||
|
|---------|----------------------|---------|
|
||||||
|
| `libsqlite3-dev` | `sudo apt install libsqlite3-dev` | `sqflite_common_ffi` busca `libsqlite3.so` (symlink que solo incluye el paquete `-dev`) |
|
||||||
|
|
||||||
|
- Aplica a desarrollo en Ubuntu desktop y posiblemente Ubuntu Touch según la imagen del dispositivo
|
||||||
|
- Sin este paquete la app compila pero crashea al inicializar la BD
|
||||||
|
- El `CMakeLists.txt` lo verifica en tiempo de compilación (`pkg_check_modules(SQLITE3 REQUIRED sqlite3)`)
|
||||||
|
- Si el usuario final no lo tiene, la app muestra un diálogo con la instrucción exacta (`settings_page.dart` → `_mostrarErrorSqlite()`)
|
||||||
|
- La BD se guarda en `~/.local/share/sentinel_one/sentinel_one.db` (estándar XDG)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Notas de arquitectura
|
## Notas de arquitectura
|
||||||
|
|
||||||
- **Tema:** Todo en `theme.dart` — siempre `AppColors`, `appHeadline()`, `appLabel()`
|
- **Tema:** Todo en `theme.dart` — siempre `AppColors`, `appHeadline()`, `appLabel()`
|
||||||
@@ -410,6 +442,19 @@ lib/
|
|||||||
- ✅ Cerrar sesión con diálogo de confirmación — limpia autologin y regresa a LoginPage
|
- ✅ Cerrar sesión con diálogo de confirmación — limpia autologin y regresa a LoginPage
|
||||||
- ✅ Fix Linux desktop: `primary: false` en todos los `SingleChildScrollView` del IndexedStack
|
- ✅ Fix Linux desktop: `primary: false` en todos los `SingleChildScrollView` del IndexedStack
|
||||||
- ✅ Fix Linux SQLite: detección de plataforma en `database_helper.dart` con `sqflite_common_ffi`
|
- ✅ Fix Linux SQLite: detección de plataforma en `database_helper.dart` con `sqflite_common_ffi`
|
||||||
|
- ✅ Fix BD Linux: ruta corregida a `~/.local/share/sentinel_one/` (antes usaba `Directory.current` impredecible)
|
||||||
|
- ✅ Fix BD Linux settings: misma corrección de ruta en `settings_page.dart` → `_confirmarInicializarBd()`
|
||||||
|
- ✅ Error SQLite amigable: si falta `libsqlite3.so` muestra diálogo con instrucción `sudo apt install libsqlite3-dev`
|
||||||
|
- ✅ ApplicationId: `com.example.seguridad_electronica` → `net.siaxsystem.sentinelone`
|
||||||
|
- ✅ Login UX: foco automático al primer campo al abrir, click en card → foco, Enter → login
|
||||||
|
- ✅ Perfil conectado a BD: carga nombre real, edición con recálculo de iniciales, `sincronizado=false` al guardar
|
||||||
|
- ✅ Historial de sesiones: página nueva con tarjetas, badge "ACTIVA", duración calculada, pull to refresh
|
||||||
|
- ✅ Ayuda y soporte → navega a MensajeriaPage
|
||||||
|
- ✅ InicioPage: nombre real desde BD (fallback "Usuario"), click en avatar → tab PERFIL
|
||||||
|
- ✅ BD v2: tablas `clientes` y `suscripciones` con migración `onUpgrade`
|
||||||
|
- ✅ Modelos: `cliente.dart`, `suscripcion.dart` (con props calculadas `vencida` y `activa`)
|
||||||
|
- ✅ DAOs: `ClientesDao`, `SuscripcionesDao` (con `getProximasAVencer()`, `cambiarEstado()`)
|
||||||
|
- ✅ Seed v2: 3 clientes, 5 suscripciones con estados variados
|
||||||
|
|
||||||
## Roadmap de autenticación (Login)
|
## Roadmap de autenticación (Login)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user