Code will explain all:
//modal for list
class MyModal
{
int myField1;
List adjacentNodes;
MyModal(this.myField1)
{
adjacentNodes= new Lis
class MyModal {
int myField1;
String myField2;
List adjacentNodes;
MyModal(this.myField1,this.myField2);
MyModal.clone(MyModal source) :
this.myField1 = source.myField1,
this.myField2 = source.myField2,
this.adjacentNodes = source.adjacentNodes.map((item) => new MyModal.clone(item)).toList();
}
var secondList = originalList.map((item) => new MyModal.clone(item)).toList();
If a member of MyModal
is of a non-primitive type like String
, int
, double
, num
, bool
, then the clone()
method needs to clone the instances references point to as well.
I think for your use case using immutable values is a better approach, for example with https://pub.dartlang.org/packages/built_value