import 'package:drift/drift.dart'; import 'app_database.dart'; /// Zugriff auf die Einzeilen-Einstellungstabelle (Doku 7.5): welches /// Drohnenprofil zuletzt aktiv war und welche Mission zuletzt bearbeitet /// wurde, um beide nach einem Neustart wiederherzustellen. class AppSettingsRepository { AppSettingsRepository(this._db); final AppDatabase _db; static const _rowId = 0; Future<({int? activeDroneProfileId, int? currentMissionId})> load() async { final row = await (_db.select(_db.appSettingsTable) ..where((s) => s.id.equals(_rowId))) .getSingleOrNull(); return ( activeDroneProfileId: row?.activeDroneProfileId, currentMissionId: row?.currentMissionId, ); } Future setActiveDroneProfileId(int? id) async { await _upsert(AppSettingsTableCompanion( id: const Value(_rowId), activeDroneProfileId: Value(id), )); } Future setCurrentMissionId(int? id) async { await _upsert(AppSettingsTableCompanion( id: const Value(_rowId), currentMissionId: Value(id), )); } Future _upsert(AppSettingsTableCompanion companion) async { await _db.into(_db.appSettingsTable).insertOnConflictUpdate(companion); } }