Add code example for readme
This commit is contained in:
parent
e388c716ff
commit
43909be36d
27
README.md
27
README.md
@ -5,5 +5,32 @@
|
|||||||
- [x] Support functions (getConfig, getConfigOrNull, hasConfigKey)
|
- [x] Support functions (getConfig, getConfigOrNull, hasConfigKey)
|
||||||
- [x] Support nullsafety (dart 2.12.2+)
|
- [x] Support nullsafety (dart 2.12.2+)
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```dart
|
||||||
|
import 'package:configurable/dotenv_configuration_provider.dart';
|
||||||
|
import 'package:configurable/simple_configuration_provider.dart';
|
||||||
|
import 'package:configurable/system_config.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
var key = 'app.name';
|
||||||
|
var value = 'CUBETIQ Solution';
|
||||||
|
|
||||||
|
// in-memory provider (built-in)
|
||||||
|
var simpleProvider = SimpleConfigurationProvider();
|
||||||
|
SystemConfig.setProvider(simpleProvider);
|
||||||
|
var result1 = SystemConfig.getOrNull(key, defaultValue: value);
|
||||||
|
// output: CUBETIQ Solution
|
||||||
|
print(result1);
|
||||||
|
|
||||||
|
// dotenv provider (from file .env)
|
||||||
|
var dotenvProvider = DotenvConfigurationProvider();
|
||||||
|
SystemConfig.setProvider(dotenvProvider);
|
||||||
|
var result2 = SystemConfig.getOrNull('HOME');
|
||||||
|
|
||||||
|
// output: user's home directory
|
||||||
|
print(result2);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Contributors
|
# Contributors
|
||||||
- Sambo Chea <sombochea@cubetiqs.com>
|
- Sambo Chea <sombochea@cubetiqs.com>
|
Loading…
Reference in New Issue
Block a user