Skip to content

Instantly share code, notes, and snippets.

@benznest
Last active March 24, 2019 07:06
Show Gist options
  • Save benznest/14517b3eb0d72f8da917448368b39e22 to your computer and use it in GitHub Desktop.
Save benznest/14517b3eb0d72f8da917448368b39e22 to your computer and use it in GitHub Desktop.
Factory constructor in Dart
class Universe{
String name;
static Universe u = Universe.init();
factory Universe(){
return u;
}
Universe.init(){
name = "A";
}
}
void main() {
Universe u1 = Universe();
Universe u2 = Universe();
u1.name = "B";
print(u1.name); // "B"
print(u2.name); // "B"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment