카테고리 없음

[Flutter] Arrow Functions

chaenii 2021. 3. 4. 09:56

Dart에서 Arrow Functions을 이용해 single line의 함수의 경우 간단하게 표현할 수가 있다.

예를 들어, 아래와 같은 add function을 Arrow Functions으로 표현해보려 한다.

int add() {
	return 5 + 2
}
int add() => 5 + 2;

함수에 인자를 넣는 경우에는 아래와 같은 형식으로 함수를 작성하면 된다.

int add(int n1, int n2){
	return n1 + n2
}
int add(int n1, int n2) => n1 + n2;
반응형