Skip to content

Instantly share code, notes, and snippets.

@maheshmnj
Last active October 15, 2020 13:00
Show Gist options
  • Save maheshmnj/5aaab75669cd8279d5514c329ca077bc to your computer and use it in GitHub Desktop.
Save maheshmnj/5aaab75669cd8279d5514c329ca077bc to your computer and use it in GitHub Desktop.
copying dart objects doesnt actually copy the contents of the object but gets a reference to it.
void main() {
Foo t = Foo();
t.a = ['a', 'b', 'c']; // some value
t.x = 30;
Foo t1 = t;
t1.a = ['x', 'y', 'z'];
t1.x = 20;
print(t1.a); // [x, y, z]
print(t.a); // [x, y, z]
print(t.x);
print(t1.x);
}
class Foo {
List<String> a = [];
int x = 10;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment