Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

Flutter Firebase Remote Config Fetch JSON as Map

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...