Flutter Firebase Remote Config Fetch JSON as Map

2,422

So the remote config value was fine, but in the app I had made wrong default value for test and it got fetched:

const defaultValue = {
    "title": "Hello, World!",
}
config.setDefaults({
    'test': defaultValue,
});

And it should have been:

config.setDefaults({
    'test': json.encode(defaultValue),
});

I thought it was Remote Config's fault

Share:
2,422
Dennis Barzanoff
Author by

Dennis Barzanoff

Updated on December 26, 2022

Comments

  • Dennis Barzanoff
    Dennis Barzanoff over 1 year

    In Firebase Remote Config I have a valid json field named test:

    {
        "title": "Hello, World!"
    }
    

    In the application I call jsonDecode(config.getString('test')) and it does not work because config.getString('test') spits out:

    {title=Hello, World!}
    

    I tried all possible methods on the config:

    jsonDecode(config.getAll()['test'].asString());
    

    and

    jsonDecode(config.getValue('test').asString())
    

    The app crashes since that is not valid JSON.

    • Hussnain Haidar
      Hussnain Haidar over 3 years
      jsonDecode(config.getString('test'))["data"]["title"]
    • Dennis Barzanoff
      Dennis Barzanoff over 3 years
      Nope, jsonDecode throws an exception because getString returns that strange Kotlin-like format