我正在使用 SQLITE db 构建一个应用程序,当列表中的项目更新时,我需要重绘屏幕。但不幸的是,它复制了数据库中的现有数据,当我重新启动应用程序时,它只显示更新的数据。这是我的 _readalldata 代码:
_readNoDoList() async {
List items = await db.getItems();
items.forEach((item) {
// NoDoItem noDoItem = NoDoItem.fromMap(item);
setState(() {
_itemList.add(NoDoItem.map(item));
});
// print("Db items: ${noDoItem.itemName}");
});
我打电话给:
FlatButton(
onPressed: () async {
NoDoItem newItemUpdated = NoDoItem.fromMap(
{
"itemName": _textEditingController.text,
"dateCreated" : dateFormatted(),
"id" : item.id
});
await db.updateItem(newItemUpdated); //updating the item
setState(() {
_readNoDoList(); // redrawing the screen with all items saved in the db
});
// Navigator.pop(context);
},
child: new Text("Update")),
但是单击更新按钮后但重新启动应用程序之前的屏幕截图如下:[1]:https ://i.stack.imgur.com/DNg8K.png
并且重启app后是:[2]:https ://i.stack.imgur.com/pIrR5.png
我在哪里犯了错误?