0
0
Fluttermobile~5 mins

Functions and arrow syntax in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a function in Flutter?
A function is a block of code that performs a specific task and can be reused. It helps organize code and makes it easier to read and maintain.
Click to reveal answer
beginner
How do you write a simple function with arrow syntax in Dart?
Use the arrow (=>) followed by the expression. For example: <br>int add(int a, int b) => a + b;<br>This means the function returns the result of a + b.
Click to reveal answer
beginner
What is the difference between a normal function and an arrow function in Dart?
A normal function uses curly braces and a return statement. An arrow function is a shorter way to write a function that returns a single expression without curly braces or return keyword.
Click to reveal answer
beginner
Can arrow functions have multiple statements in Dart?
No, arrow functions can only have one expression. For multiple statements, use normal function syntax with curly braces.
Click to reveal answer
beginner
Example: Convert this normal function to arrow syntax:<br>int square(int x) { return x * x; }
Using arrow syntax:<br>int square(int x) => x * x;<br>This is shorter and does the same thing.
Click to reveal answer
Which symbol is used for arrow syntax in Dart functions?
A->
B=>
C::
D==>
What does this arrow function return?<br>int triple(int n) => n * 3;
An * 3
B3
Cn + 3
DError
Can arrow functions contain multiple lines of code?
ANo, only one expression
BOnly if they return void
CYes, if wrapped in curly braces
DYes, always
Which is a valid arrow function in Dart?
Avoid greet() { print('Hello'); }
Bvoid greet() => print('Hello'); print('Bye');
Cvoid greet() => { print('Hello'); }
Dvoid greet() => print('Hello');
Why use arrow syntax in Flutter functions?
ATo write longer functions
BTo avoid using return statements in all functions
CTo make code shorter and clearer for simple returns
DTo declare variables
Explain how to write a function using arrow syntax in Dart and when it is appropriate to use it.
Think about simple functions that just return a value.
You got /4 concepts.
    Describe the difference between a normal function and an arrow function in Flutter with an example.
    Compare how you write a function with and without arrow syntax.
    You got /4 concepts.