I am consulting all the clubs registered in the database. And for every club I add it to a list of objects.
When the person deletes the club deletes the club from th
Your problem lies on Club
.
When you create List<Club> items
and later perform items.remove(clubInstance)
, internally the remove
method will use the standard object equals method implementation, which is unaware of your key.
The same would happen if you try to use items.indexOf(clubInstance)
. It will never 'find' the item, always returning -1
.
You can either change your implementation, iterating through the items to find out exactly which item you need to delete, and then remove it, OR you could implement ==
and hashCode
in the Club class.
If you intend to use club_name
as the key, adding these two lines will probably solve it.
class Club {
Club({this.club_name});
final String club_name;
// this is what you would have to add to your class:
bool operator ==(o) => o is Club && o.club_name == club_name;
int get hashCode => club_name.hashCode;
}
Note: this is unrelated to flutter or firebase, this is just dart!