flutter - 如何从颤动的地图中删除当前索引项?
问题描述
我正在使用 map 像这样迭代上面的项目,
...eventModifierProvider.selectedEvents.map((EventStore ) {
return Dismissible(
key: UniqueKey(),
onDismissed: (direction) {
eventModifierProvider.events.remove( what should be here?);
},
background: Container(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 20, 0),
child: Icon(Icons.close, size: 25, color: Colors.white),
),
decoration: BoxDecoration(color: Colors.redAccent)
),
child: Column(
children: [
TimeAndDuration(
time: "09:12",
amPm: "AM",
duration: "1 Hour 3 min",
),
ParticularDateEvent(
lectureSubject: EventStore.subject.toString(),
lectureStandard: EventStore.level.toString(),
lectureRoom: EventStore.room.toString(),
),
],
),
);
}),
其中selectedEvents map
有一个键,DateTime
值存储在EventStore
列表中。现在,我还使用Dismissible
小部件从地图中删除项目。
我怎么能在这里做到这一点?帮帮我
解决方案
您需要像这样获取索引:
int index = eventModifierProvider.selectedEvents.indexOf(e);
添加密钥
Key(index)
用索引删除它
RemoveAt(index)
我希望这是有帮助的
推荐阅读
- html - 选择字段中的选项仅在切换选项卡后出现
- c# - 如果添加到 where 子句的参数为空,则从 db 获取所有行
- python - 为什么 numpy.nextafter(0., 1.) != numpy.finfo(float).tiny?
- smartgit - SmartGit 18.2 preview 8 #13132 兼容 Mac OSX Mojave 10.14
- amazon-web-services - 无法通过 Terraform 在 cloudwatch 警报中使用单位
- python - 将 Dropout 添加到测试/推理阶段
- excel - 如何在“Application.EnableEvents”属性的更改上放置触发器
- angular - Angular Material mat-option 替代检索值
- python - 如何通过键绑定或宏退出 Python 程序或循环?键盘中断不起作用
- php - Wocomerce 在将其他特定物品添加到购物车时删除特定购物车物品