So I have a List with some Models in it
List<add_ingridients_list> added_ingridients_list = [
add_ingridients_list("a", "b", "c"),
add_ingridients_list("a", "b", "c"),
add_ingridients_list("a", "b", "c")
];
and now i want to create a function where i can delete specific models in this list by the index
i came up with a function looking like this
delete_ingredient_from_meal(int i, added_ingridients_list) {
// i is the index of the ListModel i want to delete
added_ingridients_list = added_ingridients_list.remove(i);
return added_ingridients_list;
}
but it isnt working, can someone give me an small example how this function should look like?
To remove an item from a list based on the item's index, use removeAt instead of remove.
From the List docs:
Solution:
Change:
to:
Note:
removeAtmutates the list and so you don't need to reassign theadded_ingridients_listvariable.removeAtreturns the removed value. To get the removed value, do this: