如何在Flutter中更新本地JSON字段 [英] How to update the local json field in flutter
本文介绍了如何在Flutter中更新本地JSON字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是扑朔迷离的飞镖新手,我阅读了很多网络文章和文档,但无法弄清楚如何更新JSON字段,我有一个本地JSON文件,例如
I am new to flutter and dart I read a lot of web article and documentation but didn't able to figure out how to update JSON field I have a local JSON file like
{
"category": "Happiness",
"quotes":[
{
"quote":"I hope you will find a reason to smile",
"favorite":false
},
{
"quote":"Sometimes your joy is the source of your smile, but sometimes your smile can be the source of your joy.",
"favorite":false
}]}
我想将JSON文件中的已归档收藏夹更新为true
I want to update the filed favorite to true in JSON file Is there any way to do this
推荐答案
您可以使用以下方法。按下按钮后,收藏夹
字段将更改为 true
。
You can use the following method. The field favorite
is changed to true
when the button is pressed.
FlatButton(
child: Text('Add Favourite'),
onPressed: (){
myJson['quotes'][myIndex]['favorite'] = true;
})
这篇关于如何在Flutter中更新本地JSON字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文