Migrate Lumen to Dart and Flutter 2.0

This commit is contained in:
Hadrian Burkhardt
2026-10-31 04:08:16 +01:00
parent 07e9253663
commit 302ad6d38e
145 changed files with 5856 additions and 101 deletions
+47
View File
@@ -0,0 +1,47 @@
import 'package:shared_preferences/shared_preferences.dart';
/// Flutter has its own store; the former Android `lumen.xml` is never imported.
class Progress {
Progress._(this._disk, this._values);
final SharedPreferencesAsync? _disk;
final Map<String, Object> _values;
static Future<Progress> load() async {
final disk = SharedPreferencesAsync();
return Progress._(disk, (await disk.getAll()).cast<String, Object>());
}
factory Progress.memory([Map<String, Object> values = const {}]) =>
Progress._(null, Map.of(values));
int number(String key, [int fallback = 0]) =>
(_values[key] as num?)?.toInt() ?? fallback;
double decimal(String key, [double fallback = 1]) =>
(_values[key] as num?)?.toDouble() ?? fallback;
bool flag(String key) => _values[key] == true;
String text(String key, [String fallback = '']) =>
_values[key] as String? ?? fallback;
bool contains(String key) => _values.containsKey(key);
Map<String, Object> get snapshot => Map.unmodifiable(_values);
Future<void> _writes = Future.value();
Future<void> set(String key, Object value) {
_values[key] = value;
final disk = _disk;
if (disk == null) return Future.value();
_writes = _writes.then((_) async {
switch (value) {
case bool v:
await disk.setBool(key, v);
case int v:
await disk.setInt(key, v);
case double v:
await disk.setDouble(key, v);
case String v:
await disk.setString(key, v);
default:
throw ArgumentError('Unsupported preference');
}
});
return _writes;
}
Future<void> get flushed => _writes;
}