feat: add SQLite data layer, local auth and security settings

- 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>
This commit is contained in:
Pablinux
2026-04-14 01:56:13 -05:00
co-authored by Claude Sonnet 4.6
parent 8f13d57839
commit 1184ab5fe2
35 changed files with 2735 additions and 346 deletions
+60
View File
@@ -0,0 +1,60 @@
class Alarma {
final int id;
final int zonaId;
final String tipo; // intrusion / humo / movimiento / acceso
final int severidad; // 1–5
final String timestamp;
final String estado; // activa / silenciada / resuelta
final int? resueltoPor;
final String? notas;
final bool sincronizado;
const Alarma({
required this.id,
required this.zonaId,
required this.tipo,
required this.severidad,
required this.timestamp,
this.estado = 'activa',
this.resueltoPor,
this.notas,
this.sincronizado = false,
});
factory Alarma.fromMap(Map<String, dynamic> m) => Alarma(
id: m['id'] as int,
zonaId: m['zona_id'] as int,
tipo: m['tipo'] as String,
severidad: m['severidad'] as int,
timestamp: m['timestamp'] as String,
estado: m['estado'] as String,
resueltoPor: m['resuelto_por'] as int?,
notas: m['notas'] as String?,
sincronizado: (m['sincronizado'] as int) == 1,
);
Map<String, dynamic> toMap() => {
'id': id,
'zona_id': zonaId,
'tipo': tipo,
'severidad': severidad,
'timestamp': timestamp,
'estado': estado,
'resuelto_por': resueltoPor,
'notas': notas,
'sincronizado': sincronizado ? 1 : 0,
};
Alarma copyWith({String? estado, int? resueltoPor, String? notas, bool? sincronizado}) =>
Alarma(
id: id,
zonaId: zonaId,
tipo: tipo,
severidad: severidad,
timestamp: timestamp,
estado: estado ?? this.estado,
resueltoPor: resueltoPor ?? this.resueltoPor,
notas: notas ?? this.notas,
sincronizado: sincronizado ?? this.sincronizado,
);
}