Bird
Raised Fist0
Fluttermobile~10 mins

Dart programming language overview in Flutter - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable that cannot be changed.

Flutter
final [1] = 10;
Drag options to blanks, or click blank then click option'
Avar
Bconst
Ccount
Dlet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a keyword like 'var' as a variable name.
Leaving the variable name blank.
2fill in blank
medium

Complete the code to define a function that returns a greeting string.

Flutter
String greet() {
  return [1];
}
Drag options to blanks, or click blank then click option'
A'Hello World'
BHello World
C"Hello World"
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string.
Using a variable name that is not defined.
3fill in blank
hard

Fix the error in the code to create a list of integers.

Flutter
List<int> numbers = [1];
Drag options to blanks, or click blank then click option'
A<1, 2, 3, 4>
B(1, 2, 3, 4)
C{1, 2, 3, 4}
D[1, 2, 3, 4]
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using curly braces which create a set.
4fill in blank
hard

Fill both blanks to create a map with string keys and integer values.

Flutter
Map<String, int> ages = [1];
ages['Alice'] = [2];
Drag options to blanks, or click blank then click option'
A{'Bob': 30}
B25
C40
D['Bob', 30]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a map.
Assigning a string instead of an integer value.
5fill in blank
hard

Fill all three blanks to create a conditional that prints a message if a number is positive.

Flutter
int number = 5;
if (number [1] 0) {
  print([2]);
} else {
  print([3]);
}
Drag options to blanks, or click blank then click option'
A>
B'Positive'
C'Not positive'
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Forgetting quotes around the strings in print.

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