2021-03-24 16:39:10 +07:00
|
|
|
import 'package:configurable/configurable.dart';
|
2021-03-24 14:10:25 +07:00
|
|
|
import 'package:configurable/dotenv_configuration_provider.dart';
|
|
|
|
import 'package:configurable/simple_configuration_provider.dart';
|
2021-03-24 14:17:47 +07:00
|
|
|
import 'package:configurable/system_config.dart';
|
2021-03-24 14:10:25 +07:00
|
|
|
|
2021-03-24 13:52:20 +07:00
|
|
|
void main() {
|
2021-03-24 14:10:25 +07:00
|
|
|
var key = 'app.name';
|
|
|
|
var value = 'CUBETIQ Solution';
|
|
|
|
|
2021-03-24 16:39:10 +07:00
|
|
|
/// in-memory provider (built-in)
|
2021-03-24 14:10:25 +07:00
|
|
|
var simpleProvider = SimpleConfigurationProvider();
|
2021-03-24 14:17:47 +07:00
|
|
|
SystemConfig.setProvider(simpleProvider);
|
|
|
|
var result1 = SystemConfig.getOrNull(key, defaultValue: value);
|
2021-03-24 16:39:10 +07:00
|
|
|
|
|
|
|
/// output: CUBETIQ Solution
|
2021-03-24 14:17:47 +07:00
|
|
|
print(result1);
|
2021-03-24 14:10:25 +07:00
|
|
|
|
2021-03-24 16:39:10 +07:00
|
|
|
/// get config functions
|
|
|
|
getConfig('app.title', defaultValue: 'My App Title!');
|
|
|
|
getConfigOrNull('app.null.ignore');
|
|
|
|
|
|
|
|
/// set config functions
|
|
|
|
/// support only mutable configuration provider
|
|
|
|
setConfig('my.app', 'Hello My App');
|
|
|
|
|
|
|
|
/// dotenv provider (from file .env)
|
2021-03-24 14:10:25 +07:00
|
|
|
var dotenvProvider = DotenvConfigurationProvider();
|
2021-03-24 14:17:47 +07:00
|
|
|
SystemConfig.setProvider(dotenvProvider);
|
|
|
|
var result2 = SystemConfig.getOrNull('HOME');
|
2021-03-24 14:10:25 +07:00
|
|
|
|
2021-03-24 16:39:10 +07:00
|
|
|
/// output: user's home directory
|
2021-03-24 14:17:47 +07:00
|
|
|
print(result2);
|
2021-03-24 16:39:10 +07:00
|
|
|
}
|