Shared Preferences Platform Interface - Dart
Shared Preferences Platform Interface - Dart
import 'dart:async';
import 'package:meta/meta.dart';
import 'method_channel_shared_preferences.dart';
/// Platform-specific plugins should set this with their own platform-specific
/// class that extends [SharedPreferencesStorePlatform] when they register the
mselves.
static set instance(SharedPreferencesStorePlatform value) {
if (!value.isMock) {
try {
value._verifyProvidesDefaultImplementations();
} on NoSuchMethodError catch (_) {
throw AssertionError(
'Platform interfaces must not be implemented with `implements`');
}
}
_instance = value;
}
@override
Future<bool> clear() async {
_data.clear();
return true;
}
@override
Future<Map<String, Object>> getAll() async {
return Map<String, Object>.from(_data);
}
@override
Future<bool> remove(String key) async {
_data.remove(key);
return true;
}
@override
Future<bool> setValue(String valueType, String key, Object value) async {
_data[key] = value;
return true;
}
}