Skip to content

Instantly share code, notes, and snippets.

@nunomazer
Created March 27, 2020 21:42
Show Gist options
  • Save nunomazer/5ccd2b53ed3da3d313126be436cdd8fa to your computer and use it in GitHub Desktop.
Save nunomazer/5ccd2b53ed3da3d313126be436cdd8fa to your computer and use it in GitHub Desktop.
Exemplo Dart getters e setters
class Rectangle {
num left, top, width, height;
Rectangle(this.left, this.top, this.width, this.height);
// Define two calculated properties: right and bottom.
num get right => left + width;
set right(num value) => left = value - width;
num get bottom => top + height;
set bottom(num value) => top = value - height;
}
void main() {
var rect = Rectangle(3, 4, 20, 15);
print(rect.left);
rect.right = 12;
print (rect.left);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment