From 43909be36d32444939a1c4b4d7c41ee816a11b1c Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Wed, 24 Mar 2021 14:22:56 +0700 Subject: [PATCH] Add code example for readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index b5dfba9..a64d907 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,32 @@ - [x] Support functions (getConfig, getConfigOrNull, hasConfigKey) - [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 - Sambo Chea \ No newline at end of file