Skip to content

Instantly share code, notes, and snippets.

@naushad-madakiya
Created May 15, 2018 02:37
Show Gist options
  • Save naushad-madakiya/44d3ed01dd2999489ab6fc5f344ee294 to your computer and use it in GitHub Desktop.
Save naushad-madakiya/44d3ed01dd2999489ab6fc5f344ee294 to your computer and use it in GitHub Desktop.
Intro to Dart for Java Developers: Use optional parameters (instead of overloading)
import 'dart:math';
class Rectangle {
int width;
int height;
Point origin;
// initialize construction with optional/default value
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(new Rectangle(origin: const Point(10, 20), width: 100, height: 200));
print(new Rectangle(origin: const Point(10, 10)));
print(new Rectangle(width: 200));
print(new Rectangle());
} // Included main() to suppress uncaught exception.
@naushad-madakiya
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment