Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a nullable String variable.
Flutter
String? name[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the semicolon at the end.
Using an exclamation mark instead of a semicolon.
✗ Incorrect
In Dart, to declare a nullable variable, you add a question mark after the type. The statement ends with a semicolon.
2fill in blank
mediumComplete the code to safely access the length of a nullable String variable.
Flutter
int? length = name[1].length; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dot operator directly on a nullable variable causes errors.
Using the exclamation mark forces non-null but can cause runtime errors.
✗ Incorrect
The question mark before the dot safely accesses the property only if the variable is not null.
3fill in blank
hardFix the error in the code by forcing non-null access to the variable.
Flutter
int length = name[1].length; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the safe access operator when the variable is expected to be non-null.
Forgetting to handle null values causing runtime errors.
✗ Incorrect
The exclamation mark tells Dart you are sure the variable is not null, so it can access the property directly.
4fill in blank
hardFill both blanks to provide a default value if the nullable variable is null.
Flutter
String displayName = name[1] '' [2] 'Guest';
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong operator for null fallback.
Forgetting to concatenate strings properly.
✗ Incorrect
The '??' operator returns the value on its left if not null, otherwise the right. The '+' concatenates strings.
5fill in blank
hardFill all three blanks to declare a nullable integer, assign a value, and force non-null access.
Flutter
int? count[1] 5; int total = count[2] [3] 0;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up assignment and comparison operators.
Not handling null values properly causing errors.
✗ Incorrect
Use '=' to assign, '!' to assert non-null, and '??' to provide a default if null.