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?
✗ Incorrect
The arrow syntax uses the symbol => to return a single expression from a function.
What does this arrow function return?<br>
int triple(int n) => n * 3;✗ Incorrect
The function returns the value of n multiplied by 3.
Can arrow functions contain multiple lines of code?
✗ Incorrect
Arrow functions can only have one expression. For multiple lines, use normal function syntax.
Which is a valid arrow function in Dart?
✗ Incorrect
Option D is a valid arrow function with a single expression. Option C uses curly braces incorrectly. Option B has two expressions.
Why use arrow syntax in Flutter functions?
✗ Incorrect
Arrow syntax helps write shorter and clearer code when the function returns a single expression.
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.