i am making a list in flutter from an existing list and when i used this new list and perform some action on it like change its quantity parameter it changes the parameter of existing list also. Can some one tell me where i am going wrong.
Existing list:
List<ItemsModel> originalList=[
ItemsModel(name: 'High Quality Double Spring Tummy Trimmer For Unisex',quantity: '30'),
ItemsModel(name: 'High Quality Double Spring Tummy Trimmer For Unisex',quantity: '30'),
ItemsModel(name: 'High Quality Double Spring Tummy Trimmer For Unisex',quantity: '30'),
];
New list:
List<ItemsModel> updatedItemList;
void initState() {
updatedItemList=[];
originalList.forEach((val){
updatedItemList.add(val);
});
super.initState();
}
on pressed button:
updatedItemList[i].quantity=qtyReceive
And on some button pressed i am performing this action that was updating both lists. Why??