0
   SomeObject someObject = SomeObject();
   SomeObject someObject2 = SomeObject();
   print(someObject==someObject2); //return false
   someObject.value =  1;
   someObject2.value = 2;
   print(someObject.value); //return 1
   print(someObject2.value); //return 2
   someObject=someObject2;
   print(someObject==someObject2); //return true
   someObject2.value=3;
   print(someObject.value); //return 3
   print(someObject2.value); //return 3

Could you please explain to me why after changing the value of someObject2 the value for this field in someObject also changes? Is there an easy way to create a new instance from an existing one?

Anonymous
  • 25
  • 6
  • 1
    Dart does not have copy constructors, so there is no general way to create copies of arbitrary objects. If you control the `SomeObject` class and want this ability, you should add a `.copyWith` or `.clone` method (or something similar) to that class. – jamesdlin Apr 15 '22 at 01:20

0 Answers0