Skip to content

Instantly share code, notes, and snippets.

@edutrul
Created June 2, 2018 15:01
Show Gist options
  • Save edutrul/d28e11faa62ca24698de1a1d026871c5 to your computer and use it in GitHub Desktop.
Save edutrul/d28e11faa62ca24698de1a1d026871c5 to your computer and use it in GitHub Desktop.
Dart class example
class Point {
// num is the parent class of `double` and `int`.
num x;
num y;
num z;
/**
* This is like
* Point(num x, num y, num z) {
this.x = x;
this.y = y;
this.z = z;
}
*/
Point(this.x, this.y, this.z);
/* This is named constructor! to use multiple constructor.
* We can not unfortunately do Poin(this.x) NOOO
* instead Point.origin(this.x) where "origin" is any name!
* and when instanting we may use new Point.origin()
* and of course that ignores the first constructor from above ^^.
*/
Point.origin(this.x);
}
void main() {
// Point point = new Point(); // or
// var point = new Point();
//var point = new Point.origin(4);
var point = new Point(4, 5, 6);
point.x = 8;
print(point is Point);
print(point);
print(point.x);
print(point.y);
print(point.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment