Skip to content

Commit

Permalink
enhance: simplify get functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dungngminh committed Dec 15, 2024
1 parent 24b2caf commit 81ef64e
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions lib/src/sheet_remote_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ class SheetRemoteConfig {
}.filterValues((value) => value != null));
}

/// Returns the value of the given key from the in-memory cache.
/// Return the value of the given key from the in-memory cache as a [String].
///
/// If the key is not found, return the default value.
///
/// {@template get_value}
///
/// *Parameters:*
Expand Down Expand Up @@ -125,30 +128,16 @@ class SheetRemoteConfig {
/// final value4 = config.getInt('key4');
/// print(value4); // 100
///
/// final value6 = config.getString('key5');
/// print(value6); // null
/// final value5 = config.getString('key5');
/// print(value5); // null
///
/// final value6Default = config.getString('key5', defaultValue: 'default value');
/// print(value6Default); // default value
/// final value5Default = config.getString('key5', defaultValue: 'default value');
/// print(value5Default); // default value
/// ```
/// {@endtemplate}
String? _get(String key) {
try {
final value = _inMemoryCachedConfig[key];
return value;
} catch (e) {
return null;
}
}

/// Return the value of the given key from the in-memory cache as a [String].
///
/// If the key is not found, return the default value.
///
/// {@macro get_value}
String? getString(String key, {String? defaultValue}) {
try {
final valueAtKey = _get(key);
final valueAtKey = _inMemoryCachedConfig[key];
return valueAtKey ?? defaultValue;
} catch (e) {
return defaultValue;
Expand All @@ -162,7 +151,7 @@ class SheetRemoteConfig {
/// {@macro get_value}
bool? getBool(String key, {bool? defaultValue}) {
try {
final value = _get(key);
final value = _inMemoryCachedConfig[key];
if (value == null && value!.isEmpty) return defaultValue;
final boolValue = bool.tryParse(
value,
Expand Down Expand Up @@ -209,6 +198,7 @@ class SheetRemoteConfig {
/// Return all the values from the in-memory cache.
///
/// Returns:
///
/// A [Map] containing all the values from the in-memory cache.
Map<String, String> getAll() {
return _inMemoryCachedConfig;
Expand Down

0 comments on commit 81ef64e

Please sign in to comment.