0
0
Fluttermobile~5 mins

Null safety in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is null safety in Flutter?
Null safety means the app knows which variables can be null and which cannot, helping to avoid crashes caused by unexpected null values.
Click to reveal answer
beginner
How do you declare a variable that can hold a null value in Dart?
Add a question mark (?) after the type. For example, String? name; means name can be null.
Click to reveal answer
intermediate
What happens if you try to use a nullable variable without checking for null?
The Dart compiler will show an error, preventing you from running code that might cause a crash due to null values.
Click to reveal answer
beginner
Explain the difference between String and String? in Dart.
String cannot be null, so it always has a value. String? can be null, so you must check before using it.
Click to reveal answer
intermediate
What is the purpose of the null assertion operator ! in Dart?
It tells Dart you are sure the variable is not null at that point, so it can be used as a non-null value. Use carefully to avoid runtime errors.
Click to reveal answer
Which symbol marks a variable as nullable in Dart?
A?
B!
C*
D&
What will happen if you try to assign null to a non-nullable variable?
AIt works fine
BCompile-time error
CRuntime error
DVariable becomes nullable automatically
How do you tell Dart you are sure a nullable variable is not null?
AUse the ! operator
BUse the ? operator
CUse the * operator
DUse the & operator
Which of these is a correct nullable variable declaration?
Aint age?;
Bint age;
C?int age;
Dint? age;
Why is null safety important in Flutter apps?
ATo allow all variables to be null
BTo make apps run faster
CTo prevent app crashes from null errors
DTo remove all variables
Explain how null safety helps prevent errors in Flutter apps.
Think about how the app knows if a variable can be null or not.
You got /3 concepts.
    Describe how to declare and use a nullable variable safely in Dart.
    Remember the question mark and null checks.
    You got /3 concepts.