getValue method
Get a value from RC (with fallback to cache)
Implementation
dynamic getValue(String key, {required dynamic defaultValue}) {
try {
/// If RC not ready → use cache
if (!_initialized) {
final cached = getCachedValue(key, defaultValue: defaultValue);
if (cached != null) return cached;
return defaultValue;
}
final rcValue = _remoteConfig.getValue(key);
if (rcValue.source == ValueSource.valueStatic) {
final cached = getCachedValue(key, defaultValue: defaultValue);
if (cached != null) return cached;
}
if (defaultValue is String) {
final s = rcValue.asString();
if (s.isNotEmpty) return s;
return getCachedValue(key, defaultValue: defaultValue) ?? defaultValue;
} else if (defaultValue is bool) {
return rcValue.asBool();
} else if (defaultValue is int) {
return rcValue.asInt();
} else if (defaultValue is double) {
return rcValue.asDouble();
} else {
return defaultValue;
}
} catch (e) {
debugPrint("RC getValue error: $e");
return getCachedValue(key, defaultValue: defaultValue) ?? defaultValue;
}
}