- Add offline-first SQLite architecture with DatabaseHelper singleton, 12 CREATE TABLE statements and full seed data on first launch - Add 10 models (fromMap/toMap) and 12 DAOs with CRUD + getPendientes() - Add ApiAuthService (JWT via SharedPreferences) and Sincronizador skeleton - Move login auth from SQLite to SharedPreferences with SHA-256 PIN hash; default PIN 123456, platform-independent (no native plugin required) - Add seguridad_page.dart: change PIN form (current → new → confirm) - Add Cerrar Sesión with confirmation dialog and full stack clear - Redesign settings_page.dart with AppColors dark theme; add Sistema section with "Inicializar base de datos" and "Inicializar sincronización" - Fix Linux desktop: sqflite_common_ffi with platform detection in DatabaseHelper - Fix ScrollController conflict on Linux: primary: false on all IndexedStack pages - Update plan_proyecto.md with session 2–3 progress and auth roadmap Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
244 lines
9.7 KiB
Dart
244 lines
9.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../theme.dart';
|
|
import '../main.dart' show LoginPage;
|
|
import 'settings_page.dart';
|
|
import 'seguridad_page.dart';
|
|
|
|
class PerfilUsuarioPage extends StatelessWidget {
|
|
const PerfilUsuarioPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
primary: false,
|
|
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_avatarCard(context),
|
|
const SizedBox(height: 24),
|
|
_statsGrid(),
|
|
const SizedBox(height: 32),
|
|
_seccionOpciones(context),
|
|
const SizedBox(height: 32),
|
|
_botonCerrarSesion(context),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// ── Avatar + info ───────────────────────────────────────────────────────────
|
|
Widget _avatarCard(BuildContext context) => Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceHigh,
|
|
borderRadius: BorderRadius.circular(12)),
|
|
child: Column(children: [
|
|
Stack(clipBehavior: Clip.none, children: [
|
|
Container(
|
|
width: 80, height: 80,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
gradient: const LinearGradient(
|
|
colors: [AppColors.primary, AppColors.primaryContainer],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColors.primary.withOpacity(0.3),
|
|
blurRadius: 20, spreadRadius: 2,
|
|
)
|
|
],
|
|
),
|
|
child: Center(
|
|
child: Text('JD',
|
|
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: const Icon(Icons.edit, size: 13, color: AppColors.primary),
|
|
),
|
|
),
|
|
]),
|
|
const SizedBox(height: 16),
|
|
Text('Juan Díaz',
|
|
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
|
const SizedBox(height: 4),
|
|
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',
|
|
style: appLabel(size: 10, weight: FontWeight.bold,
|
|
color: AppColors.primary, spacing: 1.5)),
|
|
),
|
|
]),
|
|
);
|
|
|
|
// ── Estadísticas ────────────────────────────────────────────────────────────
|
|
Widget _statsGrid() => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('ESTADÍSTICAS DEL TURNO',
|
|
style: appLabel(size: 10, weight: FontWeight.bold,
|
|
color: AppColors.onSurfaceVariant, spacing: 2.0)),
|
|
const SizedBox(height: 12),
|
|
Row(children: [
|
|
Expanded(child: _statItem('142', 'Alarmas\ngestionadas',
|
|
Icons.notifications_active, AppColors.primary)),
|
|
const SizedBox(width: 12),
|
|
Expanded(child: _statItem('38', 'Accesos\nautorizados',
|
|
Icons.lock_open, AppColors.secondary)),
|
|
const SizedBox(width: 12),
|
|
Expanded(child: _statItem('03', 'Alertas\nactivas',
|
|
Icons.warning, AppColors.error)),
|
|
]),
|
|
],
|
|
);
|
|
|
|
Widget _statItem(String valor, String label, IconData icon, Color color) =>
|
|
Container(
|
|
padding: const EdgeInsets.all(14),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceLow,
|
|
borderRadius: BorderRadius.circular(12)),
|
|
child: Column(children: [
|
|
Icon(icon, color: color, size: 20),
|
|
const SizedBox(height: 8),
|
|
Text(valor, style: appHeadline(size: 22, color: color)),
|
|
const SizedBox(height: 4),
|
|
Text(label, style: appLabel(size: 10), textAlign: TextAlign.center),
|
|
]),
|
|
);
|
|
|
|
// ── Opciones ────────────────────────────────────────────────────────────────
|
|
Widget _seccionOpciones(BuildContext context) => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('CUENTA',
|
|
style: appLabel(size: 10, weight: FontWeight.bold,
|
|
color: AppColors.onSurfaceVariant, spacing: 2.0)),
|
|
const SizedBox(height: 12),
|
|
_opcionItem(Icons.settings, 'Configuración',
|
|
'Notificaciones, sonido y alarmas', () {
|
|
Navigator.push(context,
|
|
MaterialPageRoute(builder: (_) => const SettingsPage()));
|
|
}),
|
|
const Divider(color: AppColors.outlineVariant, height: 1),
|
|
_opcionItem(Icons.shield_outlined, 'Seguridad',
|
|
'Cambiar PIN de acceso', () {
|
|
Navigator.push(context,
|
|
MaterialPageRoute(builder: (_) => const SeguridadPage()));
|
|
}),
|
|
const Divider(color: AppColors.outlineVariant, height: 1),
|
|
_opcionItem(Icons.history, 'Historial de sesiones',
|
|
'Últimos accesos al sistema', () {}),
|
|
const Divider(color: AppColors.outlineVariant, height: 1),
|
|
_opcionItem(Icons.help_outline, 'Ayuda y soporte',
|
|
'Manual del operador', () {}),
|
|
],
|
|
);
|
|
|
|
Widget _opcionItem(IconData icon, String titulo, String subtitulo,
|
|
VoidCallback onTap) =>
|
|
InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
child: Row(children: [
|
|
Container(
|
|
width: 40, height: 40,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceHighest,
|
|
borderRadius: BorderRadius.circular(10)),
|
|
child: Icon(icon, color: AppColors.primary, size: 20),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(titulo, style: appHeadline(size: 14)),
|
|
const SizedBox(height: 2),
|
|
Text(subtitulo, style: appLabel(size: 12)),
|
|
],
|
|
)),
|
|
const Icon(Icons.chevron_right,
|
|
color: AppColors.outlineVariant, size: 20),
|
|
]),
|
|
),
|
|
);
|
|
|
|
// ── Cerrar sesión ───────────────────────────────────────────────────────────
|
|
Widget _botonCerrarSesion(BuildContext context) => SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton.icon(
|
|
onPressed: () => _cerrarSesion(context),
|
|
icon: const Icon(Icons.logout, color: AppColors.error, size: 18),
|
|
label: Text('Cerrar Sesión',
|
|
style: appLabel(size: 14, weight: FontWeight.bold,
|
|
color: AppColors.error)),
|
|
style: OutlinedButton.styleFrom(
|
|
side: const BorderSide(color: AppColors.error, width: 1),
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
),
|
|
),
|
|
);
|
|
|
|
Future<void> _cerrarSesion(BuildContext context) async {
|
|
final confirmar = await showDialog<bool>(
|
|
context: context,
|
|
builder: (_) => AlertDialog(
|
|
backgroundColor: AppColors.surfaceHigh,
|
|
title: Text('Cerrar sesión',
|
|
style: appHeadline(size: 16, weight: FontWeight.w700)),
|
|
content: Text('¿Seguro que deseas cerrar sesión?',
|
|
style: appLabel(size: 13)),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: Text('Cancelar',
|
|
style: appLabel(size: 13, color: AppColors.onSurfaceVariant)),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: Text('Cerrar sesión',
|
|
style: appLabel(size: 13, weight: FontWeight.bold,
|
|
color: AppColors.error)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
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');
|
|
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
MaterialPageRoute(builder: (_) => const LoginPage()),
|
|
(_) => false,
|
|
);
|
|
}
|
|
}
|