【发布时间】:2020-09-30 10:06:29
【问题描述】:
问题:
1-) 我有一个来自 sqlite 数据库的数据列表,我想在 UI 中显示它们。此外,当用户关闭一张卡片时,我想将其从数据库中删除,但如果用户点击撤消,那么我想将其取回。问题是当我关闭它给出错误的卡时:
已关闭的 Dismissible 小部件仍然是树的一部分。
我搜索了这个问题的解决方案,但没有一个适合我的情况,因为我使用 Bloc 进行这些操作,而其他解决方案是关于 setState
你可以在这里看到: GIF
2-) 还有当我刷卡卡的背景色剪裁时: Photo
如何解决这些问题?
return Dismissible(
key: Key(widget.task.id.toString()),
background: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.red,
),
),
onDismissed: (direction) async {
Task copied = widget.task;
taskBloc.deleteTask(widget.task.id);
changeValue(widget.task.categoryId, false);
Flushbar(
messageText: Text('Task deleted', style: bodyText.copyWith(
color: Colors.white
)),
duration: Duration(seconds: 10),
margin: EdgeInsets.all(8),
borderRadius: 8,
icon: Icon(FontAwesomeIcons.infoCircle, color: widget.color),
flushbarStyle: FlushbarStyle.FLOATING,
dismissDirection: FlushbarDismissDirection.HORIZONTAL,
mainButton: FlatButton(
onPressed: () async {
taskBloc.addTask(copied);
changeValue(widget.task.categoryId, true);
},
child: Text('Undo', style: bodyText.copyWith(color: widget.color)),
),
)..show(context);
}),
【问题讨论】:
标签: flutter