首页 > 解决方案 > 如何从颤动的地图中删除当前索引项?

问题描述

我正在使用 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小部件从地图中删除项目。
我怎么能在这里做到这一点?帮帮我

标签: flutterdictionary

解决方案


您需要像这样获取索引:

int index = eventModifierProvider.selectedEvents.indexOf(e);

添加密钥

Key(index)

用索引删除它

RemoveAt(index)

我希望这是有帮助的


推荐阅读