Dart는 객체 지향 프로그램
const : compile 시점에 상수 처리 될 경우에 활용
final : 프로그램의 진행 중에 상수 처리 될 경우에 활용
var value = 1;
value = 'is Error?' --> type이 바뀌면 에러
var = 2; --> 재할당 ok
dynamic dynamicValue - 100;
dynamicValue = 'Hello'; --> type이 바뀌어도 재할당 가능
리턴타입 함수명 (매개변수) {
함수 내 동작할 코드
}
동기성 : 모든 코드가 순차적으로 진행되는 형태
비동기성 : 코드가 동시다발적으로 실행이 되어서 순차적으로 보장을 할 수 없는 형태
async / await / Future : 1회만 응답을 돌려받는 경우
async* / yield / Stream : 지속적으로 응답을 돌려받는 경우
Future<void> todo (int second) async {
await Future.delayed(Duration(seconds : second));
print('TODO DONE in $seocond seconds');
todo(3);
todo(1);
todo(5);
비동기성 프로그래밍은 위의 todo 함수가 동시로 실행되기 때문에 1,3,5대로 출력됨.
Stream<int> todo() async* {
int counter = 0;
while (counter <=10) {
counter++;
await Future.delayed(Duration(seconds: 1));
print('TODO is Running $counter');
yield counter;
}
print('TODO is Done');
}
todo().listen((event) {});