0
0
Fluttermobile~10 mins

Null safety in Flutter - Interactive Code Practice

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

Complete the code to declare a nullable String variable.

Flutter
String? name[1]
Drag options to blanks, or click blank then click option'
A;
B:
C!
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the semicolon at the end.
Using an exclamation mark instead of a semicolon.
2fill in blank
medium

Complete 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'
A!
B??
C.
D?
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.
3fill in blank
hard

Fix 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'
A!
B?
C.
D??
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.
4fill in blank
hard

Fill 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'
A??
B!
C+
D?
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong operator for null fallback.
Forgetting to concatenate strings properly.
5fill in blank
hard

Fill 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'
A=
B!
C??
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up assignment and comparison operators.
Not handling null values properly causing errors.