0
0
Fluttermobile~5 mins

Variables and type inference in Flutter - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a variable in Flutter?
A variable is a name that holds a value. It can store data like numbers, text, or objects that your app uses.
Click to reveal answer
beginner
How does type inference work in Flutter?
Type inference means Flutter can guess the type of a variable from the value you assign, so you don't always need to write the type explicitly.
Click to reveal answer
beginner
What keyword do you use in Flutter for a variable whose type is inferred?
You use the keyword var to declare a variable with type inference.
Click to reveal answer
intermediate
Can you change the type of a variable declared with var later?
No, once a variable is assigned a type by inference, you cannot assign a value of a different type to it later.
Click to reveal answer
intermediate
What is the difference between var and dynamic in Flutter?
var infers the type and keeps it fixed, while dynamic allows the variable to hold any type and can change at runtime.
Click to reveal answer
Which keyword lets Flutter guess the variable type automatically?
Avar
Bint
Cfinal
Dconst
What happens if you assign a string to a var variable initially holding an int?
AThe app crashes immediately
BIt works fine
CThe variable changes type to string
DFlutter throws a type error
Which keyword allows a variable to hold any type and change it later?
Avar
Bfinal
Cdynamic
Dconst
What is the type of a variable declared as var name = 'Alice';?
AString
Bint
Cdynamic
DObject
Which keyword declares a variable that cannot be changed after it is set?
Avar
Bfinal
Cdynamic
Dconst
Explain how Flutter uses type inference with the var keyword.
Think about how Flutter decides the variable's type without you writing it.
You got /3 concepts.
    Describe the difference between var and dynamic variables in Flutter.
    Consider how flexible each variable type is after declaration.
    You got /3 concepts.