2021-03-24 13:52:20 +07:00
|
|
|
import 'package:configurable/configuration_provider.dart';
|
2021-03-24 14:10:25 +07:00
|
|
|
import 'package:configurable/dotenv/dotenv.dart' show env, load;
|
2021-03-24 13:52:20 +07:00
|
|
|
|
2021-03-24 16:39:10 +07:00
|
|
|
/// Dotenv Configuration Provider
|
|
|
|
///
|
|
|
|
/// @author sombochea
|
|
|
|
/// @since 1.0.0
|
2021-03-24 13:52:20 +07:00
|
|
|
class DotenvConfigurationProvider implements ConfigurationProvider {
|
2021-03-24 16:39:10 +07:00
|
|
|
/// default constructor to load the platform environment
|
2021-03-24 14:10:25 +07:00
|
|
|
DotenvConfigurationProvider() {
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
2021-03-24 13:52:20 +07:00
|
|
|
@override
|
|
|
|
bool containsKey(String key) {
|
|
|
|
return env.containsKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String? getOrNull(String key, {String? defaultValue}) {
|
|
|
|
var value = env[key];
|
|
|
|
|
2021-03-24 16:39:10 +07:00
|
|
|
/// if value is null, then return default value
|
2021-03-24 13:52:20 +07:00
|
|
|
if (value == null) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|