Describe the bug
remoteConfig.getString('locale'); is removing the quote of the included string.
To Reproduce
Future<RemoteConfig> setupRemoteConfig() async {
final RemoteConfig remoteConfig = await RemoteConfig.instance;
// Enable developer mode to relax fetch throttling
remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: true));
remoteConfig.setDefaults(<String, dynamic>{
"welcome": "default welcome",
"hello': 'default hello",
"locale": {
"languageCode": "en",
"countryCode": "US"
},
});
return remoteConfig;
}
Expected behavior
String jsonLocaleConfig = remoteConfig.getString('locale');
_localeConfig = json.decode(jsonLocaleConfig);
Additional context
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.42.1)
[✓] Connected device (2 available)
• No issues found!
Let me know if I can provide you with more info.
Same here :/
adding the very convenient method getJsonValue(key) would be nice too... just saying :)
Hey @bounty1342 could you explain:
remoteConfig.getString('locale'); is removing the quote of the included string.
Not entirely sure what is happening?
Thanks for getting back to me.
String jsonDefaultConfig = await _loadLocaleDefautConfig();
print('Json of default config : $jsonDefaultConfig');
Map<String, dynamic> defaultConfig = json.decode(jsonDefaultConfig);
print(
'Map<String, dynamic> of default config : ${defaultConfig['locale']}');
remoteConfig.setDefaults(defaultConfig);
print('String of remoteConfig : ${remoteConfig.getString('locale')}');
try {
await remoteConfig.fetch(expiration: const Duration(hours: 5));
await remoteConfig.activateFetched();
} on FetchThrottledException catch (exception) {
// Fetch throttled.
print(exception);
} catch (exception) {
print('Unable to fetch remote config. Cached or default values will be '
'used');
}
print(
'String of remoteConfig after fetch: ${remoteConfig.getString('locale')}');
print('try to encode it: ${json.encode(remoteConfig.getString('locale'))}');
print('try to decode it: ${json.decode(remoteConfig.getString('locale'))}');
return remoteConfig;
I/flutter (25662): Json of default config : {
I/flutter (25662): "appName": "test",
I/flutter (25662): "dark_mode": false,
I/flutter (25662): "cacheActivated": true,
I/flutter (25662): "locale": {
I/flutter (25662): "languageCode": "en",
I/flutter (25662): "countryCode": "US"
I/flutter (25662): },
I/flutter (25662): Map<String, dynamic> of default config : {languageCode: en, countryCode: US}
I/flutter (25662): String of remoteConfig : {countryCode=US, languageCode=en}
I/flutter (25662): Unable to fetch remote config. Cached or default values will be used
I/flutter (25662): String of remoteConfig after fetch: {countryCode=US, languageCode=en}
I/flutter (25662): try to encode it: "{countryCode=US, languageCode=en}"
E/flutter (25662): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FormatException: Unexpected character (at character 2)
E/flutter (25662): {countryCode=US, languageCode=en}
We pass a
Note that the same config work fine when fetched, it's a copy and paste ! But if the user has no internet and no cache for the default config, it will fail to decode it.
Let me know if you need any more info, I will be glad to sort this one out.
PS : I'm on discord, if you need more reactivity.
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76, locale en)
• Flutter version 1.12.13+hotfix.9 at /Users/bounty1342/Documents/flutter
• Framework revision f139b11009 (3 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/bounty1342/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.9.1
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
firebase_remote_config: ^0.3.0+3
Hi,
Any progress on this one ?
@Ehesp Any chance to look at this one ?
My first time users with no internet would be stuck otherwise... Not a very good introduction...