* 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
[Flutter] Dart 문법 (json)
* 클래스 직렬화 (Json) - Flutter는 간단한 json 인코더와 디코더가 내장된 dart:convert 라이브러리 가짐 - fromJson : map 구조에서 새로운 User 객체 생성하기 위한 생성자 - toJson : User 객체를 map 구조로 변
cording-cossk3.tistory.com
https://cording-cossk3.tistory.com/88
[Flutter] Dart 문법 (skip, take)
* skip, take - skip : 첫 번째 (count) 요소 제외한 모든 요소 제공하는 iterable 반환, 즉 count개 요소 제외한 모든 요소 - take : 이 iterable의 첫 번째 요소 (count) 개의 lazy iterable 반환, 즉 iterable의 첫 번째 요
cording-cossk3.tistory.com
https://cording-cossk3.tistory.com/89
[Flutter] Dart 문법(??=, ??, null 인식 연산자, cascade, ..) #flutter operater ?? #flutter null #dart ..
* null 인식 연산자 : ??=, ?? * cascade (..연산자) : 자바의 builder 패턴과 유사. 객체 레퍼런스 변수 없이 바로 값 대입 가능 class Animal { var name = "dog"; var age; var sound; } main() { var a = 3; // ??= : 변수가 현재
cording-cossk3.tistory.com
https://cording-cossk3.tistory.com/90
[Flutter] Dart 문법 (stream, async*, yield)
* stream : 파이프 개념. - 값, 이벤트, 객체, 컬렉션, 맵, 오류 또는 심지어 다른 스트림에서 모든 유형의 데이터가 스트림에 의해 전달 가능 - async* : 게으른 연산. 요청이 있을 때는 연산을 미루다
cording-cossk3.tistory.com
https://cording-cossk3.tistory.com/85
[Flutter] Dart 문법 (async, Future, await, then)
* 비동기 - 아래 printWithDelay함수에서 await를 빼고 실행시키면 Future.delayed와 print가 동시에 실행되는 듯 하고, await을 넣고 실행시키면 delay가 적용된 후에 print가 실행된다. //Future : An object representing
cording-cossk3.tistory.com
'프로그래밍 > 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 |
댓글