Member-only story

FLUTTER INTERVIEW QUESTIONS

What is a (fat)arrow syntax in Dart?

=> expression

1 min readDec 19, 2019

--

For functions that contain just one expression, you can use short version with => that basically does {return expression;}

void main() {
function1(1); //arg was not 3
function2(1); //arg was not 3
function1(3); //arg was 3
function2(3); //arg was 3
}
void function1(int a) {
if (a == 3) {
print('arg was 3');
} else {
print('arg was not 3');
}
}
void function2(int a) => print('arg was ${a == 3 ? '' : 'not '}3');

πŸ“– Use https://dartpad.dartlang.org/ for testing examples πŸ“–

--

--

No responses yet