I want to copy list and make no reference even when I edit value in copied list. I tried addAll()
, List.from()
, map()
, toList()
and [...myList]
but they were unhelpful.
Edit for Clarification
Ex:
class Item{
String description;
int price;
Item(this.description, this.price);
}
List<Item> items = [
Item('item 1', 100),
Item('item 2', 200),
Item('item 3', 300),
];
List<Item> selectedItems = List.from(items);
When I edit selectedItems
original list items
shouldn't be affected, but it's not?!
selectedItems[0].price = 115;
it modifies the price of element 0 in both.