Created
March 27, 2020 21:42
-
-
Save nunomazer/5ccd2b53ed3da3d313126be436cdd8fa to your computer and use it in GitHub Desktop.
Exemplo Dart getters e setters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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