Skip to content

Instantly share code, notes, and snippets.

@eltray
Created August 1, 2019 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eltray/80ccca0ddd6d13f36ed1554ff9db8b5b to your computer and use it in GitHub Desktop.
Save eltray/80ccca0ddd6d13f36ed1554ff9db8b5b to your computer and use it in GitHub Desktop.
Learning Dart - 3 Use optional parameters (instead of overloading)
import 'dart:math';
class Rectangle {
int width;
int height;
Point origin;
Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0});
@override
String toString() =>
"Origin: ${origin.x}, ${origin.y}, width: $width, height: $height";
}
main() {
print(Rectangle(origin: Point(5, 10), width: 50, height: 40));
print(Rectangle(origin: Point(5, 10), width: 50));
print(Rectangle(origin: Point(5, 10)));
print(Rectangle());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment