Bird
Raised Fist0
Fluttermobile~20 mins

Dart programming language overview in Flutter - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Dart Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output of this Dart code snippet?
Consider the following Dart code:
void main() {
  var list = [1, 2, 3];
  var doubled = list.map((x) => x * 2).toList();
  print(doubled);
}

What will be printed to the console?
Flutter
void main() {
  var list = [1, 2, 3];
  var doubled = list.map((x) => x * 2).toList();
  print(doubled);
}
A[2, 4, 6]
B[1, 2, 3]
C[1, 4, 9]
DError: map is not a function
Attempts:
2 left
💡 Hint
The map function applies the given function to each element of the list.
❓ ui_behavior
intermediate
2:00remaining
What happens when this Flutter widget is tapped?
Given this Flutter widget code:
GestureDetector(
  onTap: () {
    print('Tapped!');
  },
  child: Container(
    width: 100,
    height: 50,
    color: Colors.blue,
  ),
)

What will happen when the blue container is tapped?
Flutter
GestureDetector(
  onTap: () {
    print('Tapped!');
  },
  child: Container(
    width: 100,
    height: 50,
    color: Colors.blue,
  ),
)
AThe console prints 'Tapped!' and the container color changes to red.
BNothing happens because onTap is not set correctly.
CThe console prints 'Tapped!' but the container color stays blue.
DThe app crashes due to missing MaterialApp widget.
Attempts:
2 left
💡 Hint
onTap prints a message but does not change the UI by itself.
❓ lifecycle
advanced
2:00remaining
Which method is called first in a StatefulWidget lifecycle?
In Flutter, when a StatefulWidget is inserted into the widget tree, which lifecycle method is called first in its State object?
AinitState()
Bbuild()
CdidChangeDependencies()
Ddispose()
Attempts:
2 left
💡 Hint
This method is called once when the State object is created.
❓ navigation
advanced
2:00remaining
What is the result of this Flutter navigation code?
Given this Flutter code snippet:
Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => SecondScreen()),
);
Navigator.pop(context);

What will happen after these two calls execute sequentially?
Flutter
Navigator.push(
  context,
  MaterialPageRoute(builder: (context) => SecondScreen()),
);
Navigator.pop(context);
AThe app crashes due to calling pop immediately after push.
BThe app navigates to SecondScreen and then immediately returns to the previous screen.
CThe app stays on the current screen without navigation.
DThe app navigates to SecondScreen and stays there.
Attempts:
2 left
💡 Hint
push adds a new screen, pop removes the current screen.
🔧 Debug
expert
2:00remaining
What error does this Dart code produce?
Analyze this Dart code:
void main() {
  int? a = null;
  int b = a! + 5;
  print(b);
}

What error will this code cause at runtime?
Flutter
void main() {
  int? a = null;
  int b = a! + 5;
  print(b);
}
ANo error; prints 5
BSyntax error: Unexpected token '!'
CCompile-time error: Cannot assign null to non-nullable int
DRuntime error: Null check operator used on a null value
Attempts:
2 left
💡 Hint
The ! operator asserts the value is not null at runtime.

Practice

(1/5)
1. What is Dart primarily used for in Flutter development?
easy
A. Writing the app's code and logic
B. Designing the app's images
C. Creating database schemas
D. Managing app deployment

Solution

  1. Step 1: Understand Dart's role

    Dart is the programming language used to write Flutter apps.
  2. Step 2: Identify what Dart does in Flutter

    Dart handles the app's code and logic, not images or deployment.
  3. Final Answer:

    Writing the app's code and logic -> Option A
  4. Quick Check:

    Dart = app code language [OK]
Hint: Dart is the language, not design or deployment [OK]
Common Mistakes:
  • Confusing Dart with design tools
  • Thinking Dart manages deployment
  • Mixing Dart with database design
2. Which of the following is the correct way to declare a variable in Dart?
easy
A. string name = 'Flutter';
B. let name = 'Flutter';
C. var name = 'Flutter';
D. dim name = 'Flutter';

Solution

  1. Step 1: Recall Dart variable syntax

    Dart uses 'var' to declare variables with inferred types.
  2. Step 2: Check each option

    'let' is JavaScript, 'string' lowercase is invalid, 'dim' is VB syntax.
  3. Final Answer:

    var name = 'Flutter'; -> Option C
  4. Quick Check:

    Use 'var' for variables in Dart [OK]
Hint: Dart uses 'var' for variables, not 'let' or 'dim' [OK]
Common Mistakes:
  • Using JavaScript 'let'
  • Using lowercase 'string'
  • Using VB 'dim'
3. What will be the output of this Dart code?
void main() {
  var list = [1, 2, 3];
  print(list.map((x) => x * 2).toList());
}
medium
A. [1, 2, 3]
B. Error: map is not a function
C. [3, 6, 9]
D. [2, 4, 6]

Solution

  1. Step 1: Understand the map function

    map applies the function (x * 2) to each element in the list.
  2. Step 2: Calculate the mapped list

    1*2=2, 2*2=4, 3*2=6, so the new list is [2, 4, 6].
  3. Final Answer:

    [2, 4, 6] -> Option D
  4. Quick Check:

    map doubles each element = [2,4,6] [OK]
Hint: map applies function to each list item [OK]
Common Mistakes:
  • Confusing map with filter
  • Expecting original list
  • Thinking map causes error
4. Identify the error in this Dart code snippet:
void main() {
  int number = '5';
  print(number);
}
medium
A. Missing semicolon after print statement
B. Cannot assign a String to an int variable
C. Variable 'number' is not declared
D. print() function is undefined

Solution

  1. Step 1: Check variable assignment types

    Variable 'number' is declared as int but assigned a String '5'.
  2. Step 2: Understand Dart type safety

    Dart does not allow assigning a String to an int variable without conversion.
  3. Final Answer:

    Cannot assign a String to an int variable -> Option B
  4. Quick Check:

    Type mismatch error = Cannot assign a String to an int variable [OK]
Hint: Check variable types match assigned values [OK]
Common Mistakes:
  • Ignoring type mismatch
  • Thinking semicolon missing
  • Assuming print undefined
5. How can you create a Dart function that returns the sum of two numbers only if both are positive, otherwise returns zero?
hard
A. int sum(int a, int b) => (a > 0 && b > 0) ? a + b : 0;
B. int sum(int a, int b) { if (a > 0 || b > 0) return a + b; else return 0; }
C. int sum(int a, int b) => a + b;
D. int sum(int a, int b) { return a > 0 && b > 0 ? a - b : 0; }

Solution

  1. Step 1: Understand the condition

    Sum only if both a and b are positive (greater than 0).
  2. Step 2: Check each option's logic

    int sum(int a, int b) => (a > 0 && b > 0) ? a + b : 0; uses correct '&&' and returns sum or 0. Others use '||' (wrong condition), always sum, or subtract instead of add.
  3. Final Answer:

    int sum(int a, int b) => (a > 0 && b > 0) ? a + b : 0; -> Option A
  4. Quick Check:

    Use '&&' for both positive check [OK]
Hint: Use '&&' to check both positive before summing [OK]
Common Mistakes:
  • Using '||' instead of '&&'
  • Always summing without condition
  • Subtracting instead of adding
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard