Implement basic settings
This commit is contained in:
28
lib/db.dart
28
lib/db.dart
@@ -28,6 +28,11 @@ CREATE TABLE IF NOT EXISTS scratches (
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_scratches_date ON scratches (date);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS settings (
|
||||
key TEXT PRIMARY KEY NOT NULL,
|
||||
value TEXT NOT NULL
|
||||
);
|
||||
''';
|
||||
|
||||
static Future<String> _getDatabasePath() async {
|
||||
@@ -83,4 +88,27 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// Settings Management
|
||||
static Future<String?> getSetting(String key) async {
|
||||
final List<Map<String, dynamic>> maps = await db.query(
|
||||
'settings',
|
||||
columns: ['value'],
|
||||
where: 'key = ?',
|
||||
whereArgs: [key],
|
||||
);
|
||||
if (maps.isNotEmpty) {
|
||||
return maps.first['value'] as String?;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<void> setSetting(String key, String value) async {
|
||||
await db.insert(
|
||||
'settings',
|
||||
{'key': key, 'value': value},
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
debugPrint("Setting updated: $key = $value");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user