configurable/lib/simple_configuration_provid...
Sambo Chea 1be7ecaa33 - Fixed simple provider for final configs variable
- Fixed setAll function that set itself, in simple provider
2021-03-25 13:35:22 +07:00

48 lines
954 B
Dart

import 'package:configurable/mutable_configurable_provider.dart';
/// Simple Configuration Provider
///
/// @author sombochea
/// @since 1.0.0
class SimpleConfigurationProvider implements MutableConfigurationProvider {
final 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);
}
}