Aman Chaudhary
Aman Chaudhary

Reputation: 912

How to remove the current index item from a map in flutter?

I am using map for iterating the items on it like this,

...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(),
                      ),
                    ],
                  ),
                );
              }),

In the selectedEvents map there is a key of DateTime and values are stored in EventStore list. Now, I am also using the Dismissible widget for removing the item from the map.
How can I do that here? Do help me

Upvotes: 0

Views: 1771

Answers (1)

Aldy Yuan
Aldy Yuan

Reputation: 2055

You need to get the index like this:

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

Add the key

Key(index)

Remove it with index

RemoveAt(index)

I hope this is helpful

Upvotes: 1

Related Questions