configurable/lib/simple_configuration_provid...
Sambo Chea 649f25b265 - Add mutable configuration provider
- Split tests file
- Fixed and nullable functions
- Able to set or remove config from system config
2021-03-24 16:39:10 +07:00

48 lines
940 B
Dart

import 'package:configurable/mutable_configurable_provider.dart';
/// Simple Configuration Provider
///
/// @author sombochea
/// @since 1.0.0
class SimpleConfigurationProvider implements MutableConfigurationProvider {
Map<String, String?> configs = {};
@override
String? getOrNull(String key, {String? defaultValue}) {
var value = configs[key];
/// if value is null, then set the default value and return it back
if (value == null) {
configs[key] = defaultValue;
return defaultValue;
}
return value;
}
@override
bool containsKey(String key) {
return configs.containsKey(key);
}
@override
void set(String key, String? value) {
configs[key] = value;
}
@override
void remove(String key) {
configs.remove(key);
}
@override
void removeAll() {
configs.clear();
}
@override
void setAll(Map<String, String?> configs) {
configs.addAll(configs);
}
}