- 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>
63 lines
1.6 KiB
Dart
63 lines
1.6 KiB
Dart
import '../database_helper.dart';
|
|
import '../../models/evento.dart';
|
|
|
|
class EventosDao {
|
|
final _db = DatabaseHelper.instance;
|
|
|
|
Future<List<Evento>> getAll() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', orderBy: 'timestamp DESC');
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<List<Evento>> getRecientes({int limit = 10}) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query(
|
|
'eventos',
|
|
orderBy: 'timestamp DESC',
|
|
limit: limit,
|
|
);
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<Evento?> getById(int id) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', where: 'id = ?', whereArgs: [id]);
|
|
return rows.isEmpty ? null : Evento.fromMap(rows.first);
|
|
}
|
|
|
|
Future<int> insert(Evento e) async {
|
|
final db = await _db.db;
|
|
return db.insert('eventos', e.toMap());
|
|
}
|
|
|
|
Future<int> marcarLeido(int id) async {
|
|
final db = await _db.db;
|
|
return db.update(
|
|
'eventos',
|
|
{'leido': 1, 'sincronizado': 0},
|
|
where: 'id = ?',
|
|
whereArgs: [id],
|
|
);
|
|
}
|
|
|
|
Future<int> delete(int id) async {
|
|
final db = await _db.db;
|
|
return db.delete('eventos', where: 'id = ?', whereArgs: [id]);
|
|
}
|
|
|
|
Future<List<Evento>> getPendientes() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('eventos', where: 'sincronizado = 0');
|
|
return rows.map(Evento.fromMap).toList();
|
|
}
|
|
|
|
Future<int> contarNoLeidos() async {
|
|
final db = await _db.db;
|
|
final result = await db.rawQuery(
|
|
'SELECT COUNT(*) as c FROM eventos WHERE leido = 0',
|
|
);
|
|
return result.first['c'] as int;
|
|
}
|
|
}
|