in https://dartpad.dartlang.org/ editor I typed below to test my issue.
based on my testing apparently list.from function only create a NEW copy when the T is not object/class
I tested list.from for List it works like charm but not class/object.
please let me know how to create a new copy of the list of T below code so that when we change the list in one place, the other place does not get change.
thanks
void main() {
List<Status> statuses = <Status>[
Status(name: 'Confirmed', isCheck: true),
Status(name: 'Cancelled', isCheck: true),
];
print('statuses = ${statuses.toList().map((x) => x.name + '=' + x.isCheck.toString())}');
//this supposed to create a new list of T but apparently only work for non-object
List<Status> otherStatuses = new List<Status>.from(statuses);
print('otherStatuses= ${otherStatuses.toList().map((x) => x.name + '=' + x.isCheck.toString())}');
otherStatuses.singleWhere((x)=>x.name=='Cancelled').isCheck=false;
print('after the changes only on otherStatuses');
print('statuses = ${statuses.toList().map((x) => x.name + '=' + x.isCheck.toString())}');
print('statuses2 = ${otherStatuses.toList().map((x) => x.name + '=' + x.isCheck.toString())}');
print('why the original status (cancelled) equal to false?');
}
class Status {
String name;
bool isCheck;
Status({
this.name,
this.isCheck,
});
}