import 'package:nc_photos/entity/pref.dart'; import 'package:np_common/type.dart'; /// [Pref] stored in memory, useful in unit tests class PrefMemoryProvider extends PrefProvider { PrefMemoryProvider([ Map initialData = const {}, ]) : _data = Map.of(initialData); factory PrefMemoryProvider.fromJson(JsonObj json) => PrefMemoryProvider(json); @override bool? getBool(PrefKeyInterface key) => _get(key); @override Future setBool(PrefKeyInterface key, bool value) => _set(key, value); @override int? getInt(PrefKeyInterface key) => _get(key); @override Future setInt(PrefKeyInterface key, int value) => _set(key, value); @override String? getString(PrefKeyInterface key) => _get(key); @override Future setString(PrefKeyInterface key, String value) => _set(key, value); @override List? getStringList(PrefKeyInterface key) => _get>(key); @override Future setStringList(PrefKeyInterface key, List value) => _set(key, value); @override Future remove(PrefKeyInterface key) async { _data.remove(key.toStringKey()); return true; } @override Future clear() async { _data.clear(); return true; } T? _get(PrefKeyInterface key) => _data[key.toStringKey()]; Future _set(PrefKeyInterface key, T value) async { _data[key.toStringKey()] = value; return true; } final Map _data; }