Compare commits
No commits in common. "master" and "1d41d08666841632d3951bab31a3f810fc0bd901" have entirely different histories.
master
...
1d41d08666
15
CHANGELOG.md
15
CHANGELOG.md
@ -19,18 +19,3 @@
|
||||
|
||||
## 1.0.4
|
||||
- Fixed format classes and files
|
||||
|
||||
## 1.0.5
|
||||
- Fixed simple provider for final configs variable
|
||||
- Fixed setAll function that set itself, in simple provider
|
||||
|
||||
## 1.0.6
|
||||
- Add async function support
|
||||
- Add functions for set and remove for system config and file functions
|
||||
- Add TextFormatter for format the string with args
|
||||
|
||||
## 1.0.7
|
||||
- Removed example "example_flutter_secure_storage_provider.dart"
|
||||
|
||||
## 1.0.8
|
||||
- Fixed Text Formatter on dynamic to string
|
@ -8,13 +8,9 @@
|
||||
- [x] Support functions (getConfig, getConfigOrNull, hasConfigKey, setConfig)
|
||||
- [x] Support nullsafety (dart 2.12.2+)
|
||||
- [x] Custom configuration provider
|
||||
- [x] Add Async functions support
|
||||
|
||||
# Issue
|
||||
- Flutter app not support for dotenv (.env) when run on devices (because of runtime in device)
|
||||
|
||||
# Resolution
|
||||
- Flutter app can be use persistence storage like SharedPreference or FlutterSecureStorage to implement the configuration provider
|
||||
- Flutter app not support for dotenv (.env) when run on devices
|
||||
|
||||
# Example
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
import 'package:configurable/text_formatter.dart';
|
||||
|
||||
void main(List<String> args) {
|
||||
var text1 = 'Hello, {0}, then do this it by {1}!';
|
||||
var text2 = 'Hello, {firstName}, then do this it by {lastName}!';
|
||||
var result1 = TextFormatter(text1).format(['Sambo', 'Chea']);
|
||||
var result2 = TextFormatter(text2).decorate({
|
||||
'firstName': 'Sambo',
|
||||
'lastName': 'Chea',
|
||||
});
|
||||
|
||||
print('Result 1 => $result1');
|
||||
print('Result 2 => $result2');
|
||||
}
|
@ -6,11 +6,6 @@ import 'package:configurable/system_config.dart';
|
||||
String? getConfigOrNull(String key, {String? defaultValue}) =>
|
||||
SystemConfig.getOrNull(key, defaultValue: defaultValue);
|
||||
|
||||
/// get config or null from system config in async
|
||||
Future<String?> getConfigOrNullAsync(String key,
|
||||
{String? defaultValue}) async =>
|
||||
await SystemConfig.getOrNullAsync(key, defaultValue: defaultValue);
|
||||
|
||||
/// get config with non-null from system config
|
||||
String getConfig(String key, {String? defaultValue}) =>
|
||||
SystemConfig.get(key, defaultValue: defaultValue);
|
||||
@ -18,20 +13,5 @@ String getConfig(String key, {String? defaultValue}) =>
|
||||
/// check has config key or not from system config
|
||||
bool hasConfigkey(String key) => SystemConfig.containsKey(key);
|
||||
|
||||
/// check has config key or not from system config in async function
|
||||
Future<bool> hasConfigkeyAsync(String key) async =>
|
||||
await SystemConfig.containsKeyAsync(key);
|
||||
|
||||
/// set config into memory or custom provider
|
||||
/// set config into memory
|
||||
void setConfig(String key, String? value) => SystemConfig.set(key, value);
|
||||
|
||||
/// set config into memory or custom provider in async function
|
||||
Future<void> setConfigAsync(String key, String? value) async =>
|
||||
await SystemConfig.setAsync(key, value);
|
||||
|
||||
/// remove config into memory or custom provider
|
||||
void removeConfig(String key) => SystemConfig.remove(key);
|
||||
|
||||
/// remove config into memory or custom provider in async function
|
||||
Future<void> removeConfigAsync(String key) async =>
|
||||
await SystemConfig.removeAsync(key);
|
||||
|
@ -8,14 +8,4 @@ abstract class ConfigurationProvider {
|
||||
|
||||
/// get or null in implemented classes
|
||||
String? getOrNull(String key, {String? defaultValue});
|
||||
|
||||
/// check has key or not for async function
|
||||
Future<bool> containsKeyAsync(String key) async {
|
||||
return Future.value(containsKey(key));
|
||||
}
|
||||
|
||||
/// get or null for async function
|
||||
Future<String?> getOrNullAsync(String key, {String? defaultValue}) async {
|
||||
return Future.value(getOrNull(key, defaultValue: defaultValue));
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import 'package:configurable/dotenv/dotenv.dart' show env, load;
|
||||
///
|
||||
/// @author sombochea
|
||||
/// @since 1.0.0
|
||||
class DotenvConfigurationProvider extends ConfigurationProvider {
|
||||
class DotenvConfigurationProvider implements ConfigurationProvider {
|
||||
/// default constructor to load the platform environment
|
||||
DotenvConfigurationProvider() {
|
||||
load();
|
||||
|
@ -4,42 +4,16 @@ import 'package:configurable/configuration_provider.dart';
|
||||
///
|
||||
/// @author sombochea
|
||||
/// @since 1.0.3
|
||||
abstract class MutableConfigurationProvider extends ConfigurationProvider {
|
||||
abstract class MutableConfigurationProvider implements ConfigurationProvider {
|
||||
/// Allow to set the value into config values
|
||||
void set(String key, String? value);
|
||||
|
||||
/// Allow to set all values into config values
|
||||
void setAll(Map<String, String?> configs) {
|
||||
configs.forEach((key, value) {
|
||||
set(key, value);
|
||||
});
|
||||
}
|
||||
void setAll(Map<String, String?> configs);
|
||||
|
||||
/// Allow to remove the key from config values
|
||||
void remove(String key);
|
||||
|
||||
/// Allow to remove all values from config values
|
||||
void removeAll();
|
||||
|
||||
/// Allow to set the value into config values in async function
|
||||
Future<void> setAsync(String key, String? value) async {
|
||||
set(key, value);
|
||||
}
|
||||
|
||||
/// Allow to set all values into config values in async function
|
||||
Future<void> setAllAsync(Map<String, String?> configs) async {
|
||||
configs.forEach((key, value) {
|
||||
setAsync(key, value);
|
||||
});
|
||||
}
|
||||
|
||||
/// Allow to remove the key from config values in async function
|
||||
Future<void> removeAsync(String key) async {
|
||||
remove(key);
|
||||
}
|
||||
|
||||
/// Allow to remove all values from config values in async function
|
||||
Future<void> removeAllAsync() async {
|
||||
removeAll();
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ import 'package:configurable/mutable_configurable_provider.dart';
|
||||
///
|
||||
/// @author sombochea
|
||||
/// @since 1.0.0
|
||||
class SimpleConfigurationProvider extends MutableConfigurationProvider {
|
||||
final Map<String, String?> _configs = {};
|
||||
class SimpleConfigurationProvider implements MutableConfigurationProvider {
|
||||
Map<String, String?> configs = {};
|
||||
|
||||
@override
|
||||
String? getOrNull(String key, {String? defaultValue}) {
|
||||
var value = _configs[key];
|
||||
var value = configs[key];
|
||||
|
||||
/// if value is null, then set the default value and return it back
|
||||
if (value == null) {
|
||||
_configs[key] = defaultValue;
|
||||
configs[key] = defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@ -22,26 +22,26 @@ class SimpleConfigurationProvider extends MutableConfigurationProvider {
|
||||
|
||||
@override
|
||||
bool containsKey(String key) {
|
||||
return _configs.containsKey(key);
|
||||
return configs.containsKey(key);
|
||||
}
|
||||
|
||||
@override
|
||||
void set(String key, String? value) {
|
||||
_configs[key] = value;
|
||||
configs[key] = value;
|
||||
}
|
||||
|
||||
@override
|
||||
void remove(String key) {
|
||||
_configs.remove(key);
|
||||
configs.remove(key);
|
||||
}
|
||||
|
||||
@override
|
||||
void removeAll() {
|
||||
_configs.clear();
|
||||
configs.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
void setAll(Map<String, String?> configs) {
|
||||
_configs.addAll(configs);
|
||||
configs.addAll(configs);
|
||||
}
|
||||
}
|
||||
|
@ -30,15 +30,8 @@ class SystemConfig {
|
||||
return getProvider().getOrNull(key, defaultValue: defaultValue);
|
||||
}
|
||||
|
||||
static Future<String?> getOrNullAsync(String key, {String? defaultValue}) {
|
||||
return getProvider().getOrNullAsync(key, defaultValue: defaultValue);
|
||||
}
|
||||
|
||||
static bool containsKey(String key) => getProvider().containsKey(key);
|
||||
|
||||
static Future<bool> containsKeyAsync(String key) =>
|
||||
getProvider().containsKeyAsync(key);
|
||||
|
||||
/// Convert to mutable configuration provider
|
||||
static MutableConfigurationProvider _getMutableConfigurationProvider() {
|
||||
if (_provider is MutableConfigurationProvider) {
|
||||
@ -53,31 +46,7 @@ class SystemConfig {
|
||||
_getMutableConfigurationProvider().set(key, value);
|
||||
}
|
||||
|
||||
static Future<void> setAsync(String key, String? value) async {
|
||||
await _getMutableConfigurationProvider().setAsync(key, value);
|
||||
}
|
||||
|
||||
static void setAll(Map<String, String?> values) {
|
||||
_getMutableConfigurationProvider().setAll(values);
|
||||
}
|
||||
|
||||
static Future<void> setAllAsync(Map<String, String?> values) async {
|
||||
await _getMutableConfigurationProvider().setAllAsync(values);
|
||||
}
|
||||
|
||||
static void remove(String key) {
|
||||
_getMutableConfigurationProvider().remove(key);
|
||||
}
|
||||
|
||||
static Future<void> removeAsync(String key) async {
|
||||
await _getMutableConfigurationProvider().removeAsync(key);
|
||||
}
|
||||
|
||||
static void removeAll() {
|
||||
_getMutableConfigurationProvider().removeAll();
|
||||
}
|
||||
|
||||
static Future<void> removeAllAsync() async {
|
||||
await _getMutableConfigurationProvider().removeAllAsync();
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
class TextFormatter {
|
||||
String? text;
|
||||
|
||||
TextFormatter(String? text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
String? format(List<dynamic> args) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.isEmpty) {
|
||||
return text;
|
||||
}
|
||||
|
||||
var msg = text;
|
||||
args.asMap().forEach((index, element) {
|
||||
var _replaced = '';
|
||||
if (element != null) {
|
||||
_replaced = element.toString();
|
||||
}
|
||||
|
||||
msg = msg?.replaceAll('{$index}', _replaced);
|
||||
});
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
String? decorate(Map<String, dynamic> params) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (params.isEmpty) {
|
||||
return text;
|
||||
}
|
||||
|
||||
var msg = text;
|
||||
params.forEach((index, element) {
|
||||
var _replaced = '';
|
||||
if (element != null) {
|
||||
_replaced = element.toString();
|
||||
}
|
||||
|
||||
msg = msg?.replaceAll('{$index}', _replaced);
|
||||
});
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
name: configurable
|
||||
description: System Configuration, Dotenv Environment and Text Formatter for Dart and Flutter
|
||||
version: 1.0.8
|
||||
description: System Configuration and Dotenv Environment for Dart and Flutter
|
||||
version: 1.0.4
|
||||
homepage: https://github.com/CUBETIQ/system-config-dart
|
||||
repository: https://github.com/CUBETIQ/system-config-dart.git
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
import 'package:configurable/configurable.dart'
|
||||
show
|
||||
getConfigOrNullAsync,
|
||||
hasConfigkeyAsync,
|
||||
setConfigAsync,
|
||||
removeConfigAsync;
|
||||
import 'package:configurable/simple_configuration_provider.dart';
|
||||
import 'package:configurable/system_config.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('get system config by key', () async {
|
||||
var key = 'app.name';
|
||||
var value = 'CUBETIQ';
|
||||
|
||||
// set simple provider
|
||||
SystemConfig.setProvider(SimpleConfigurationProvider());
|
||||
|
||||
var result = await SystemConfig.getOrNullAsync(key, defaultValue: value);
|
||||
|
||||
expect(value, equals(result));
|
||||
expect(value, equals(await SystemConfig.getOrNullAsync(key)));
|
||||
});
|
||||
|
||||
test('get config by key with function', () async {
|
||||
var key = 'app.name';
|
||||
var value = 'CUBETIQ Solution';
|
||||
|
||||
// set simple provider
|
||||
SystemConfig.setProvider(SimpleConfigurationProvider());
|
||||
|
||||
var result = await getConfigOrNullAsync(key, defaultValue: value);
|
||||
|
||||
expect(value, equals(result));
|
||||
expect(true, equals(await hasConfigkeyAsync(key)));
|
||||
expect(value, equals(await getConfigOrNullAsync(key)));
|
||||
});
|
||||
|
||||
test('set config by key and value with function', () async {
|
||||
var key = 'app.name';
|
||||
var value = 'CUBETIQ Solution';
|
||||
|
||||
// set simple provider
|
||||
SystemConfig.setProvider(SimpleConfigurationProvider());
|
||||
|
||||
await setConfigAsync(key, value);
|
||||
|
||||
var result = await getConfigOrNullAsync(key);
|
||||
|
||||
expect(value, equals(result));
|
||||
});
|
||||
|
||||
test('set and then remove config by key and value with function', () async {
|
||||
var key = 'app.name';
|
||||
var value = 'CUBETIQ Solution';
|
||||
|
||||
// set simple provider
|
||||
SystemConfig.setProvider(SimpleConfigurationProvider());
|
||||
|
||||
await setConfigAsync(key, value);
|
||||
|
||||
var result = await getConfigOrNullAsync(key);
|
||||
|
||||
expect(value, equals(result));
|
||||
|
||||
await removeConfigAsync(key);
|
||||
|
||||
expect(null, equals(await getConfigOrNullAsync(key)));
|
||||
});
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import 'package:configurable/text_formatter.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('text formatter function format', () {
|
||||
var text1 = 'Hello, {0}!';
|
||||
var result1 = TextFormatter(text1).format(['Sambo']);
|
||||
|
||||
var text2 = 'Hello, {name}!';
|
||||
var result2 = TextFormatter(text2).decorate({'name': 'Chea'});
|
||||
|
||||
expect('Hello, Sambo!', result1);
|
||||
expect('Hello, Chea!', result2);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user