* getter, setter
class Rectangle {
double left, top, width, height;
Rectangle(this.left, this.top, this.width, this.height);
//Define two calculated properties : right and bottom.
double get right => left + width;
set right(double value) => left = value - width;
double get bottom => top + height;
set bottom(double value) => top = value - height;
void printRectangle() {
print("====================");
print("rect (l,t,r,b): " +
left.toString() +
", " +
top.toString() +
", " +
right.toString() +
". " +
bottom.toString());
print("rect (w,h) : " + width.toString() + ", " + height.toString());
print("====================");
print("\n");
}
void printTest() {
print("Hello Test!");
}
}
void main() {
var rect = Rectangle(3, 4, 20, 15);
assert(rect.left == 3);
rect.printRectangle();
rect.right = 12;
assert(rect.left == -8);
rect.printRectangle();
}
//결과
====================
rect (l,t,r,b): 3.0, 4.0, 23.0. 19.0
rect (w,h) : 20.0, 15.0
====================
====================
rect (l,t,r,b): -8.0, 4.0, 12.0. 19.0
rect (w,h) : 20.0, 15.0
====================
같이 보면 좋은 포스팅
https://cording-cossk3.tistory.com/87
https://cording-cossk3.tistory.com/88
https://cording-cossk3.tistory.com/89
https://cording-cossk3.tistory.com/90
https://cording-cossk3.tistory.com/85
320x100
'프로그래밍 > Flutter-Dart' 카테고리의 다른 글
[Flutter] Dart 문법 (skip, take) (0) | 2021.03.15 |
---|---|
[Flutter] Dart 문법 (json) (0) | 2021.03.15 |
[Flutter] Dart 문법 (async, Future, await, then) (0) | 2021.03.15 |
[Flutter] Dart 문법 (abstract, implement) (0) | 2021.03.15 |
[Flutter] Dart 문법 (상속) (0) | 2021.03.15 |
댓글