Reputation: 2431
I want to cast RemoteConfigValue
to Flutter Map<String, dynamic>
as I am using Firebase remote config set JSON
data as a value in the firebase console.
I not getting any function with gives me JSON/Map value instead of RemoteConfigValue.
final RemoteConfig remoteConfig = await RemoteConfig.instance;
remoteConfig.setDefaults(<String, dynamic>{});
try {
await remoteConfig.fetch(expiration: const Duration(seconds: 0));
await remoteConfig.activateFetched();
print(remoteConfig.getValue("MyKey"));
} on FetchThrottledException catch (exception) {
print(exception.toString());
} catch (exception) {
print(exception.toString());
}
Upvotes: 0
Views: 2561
Reputation: 2431
I figured it out -
Step 1: get string value from RemoteConfigValue
like remoteConfig.getString("UAE")
this or remoteConfig.getValue("UAE").asString()
like this
Step 2: cast that string value into Map
using json.decode
:
Example:
Map<String, dynamic> mapValues = json.decode(remoteConfig.getValue("MyKey").asString());
print(mapValues["countryName"]);
Upvotes: 4