0
0
Fluttermobile~20 mins

Variables and type inference in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variables and Type Inference Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
1:30remaining
Understanding Dart variable type inference
What is the type of variable x after this code runs?
var x = 42;
Flutter
var x = 42;
Adynamic
Bdouble
Cint
DString
Attempts:
2 left
💡 Hint
Dart infers the type from the assigned value.
ui_behavior
intermediate
1:30remaining
Effect of variable type on Flutter widget display
Given this Flutter code snippet, what will be displayed on the screen?
var message = 123;
return Text(message.toString());
Flutter
var message = 123;
return Text(message.toString());
AThe number 123 as text
BAn error because Text expects a String variable
CNothing is displayed
DThe word 'message' is displayed
Attempts:
2 left
💡 Hint
Check how the integer is converted to text.
lifecycle
advanced
2:00remaining
Variable type and widget rebuild behavior
In a Flutter StatefulWidget, if you declare a variable with var count = 0; inside the State class and update it inside setState(), what happens to the variable type during rebuilds?
Flutter
class _MyWidgetState extends State<MyWidget> {
  var count = 0;

  void increment() {
    setState(() {
      count++;
    });
  }
}
AThe variable type changes to dynamic after first rebuild
BThe variable type remains int across rebuilds
CThe variable is reset to 0 on every rebuild
DThe variable becomes null after rebuild
Attempts:
2 left
💡 Hint
Consider where the variable is declared and how Flutter rebuilds widgets.
🔧 Debug
advanced
2:00remaining
Identifying type inference error in Dart
What error will this Dart code produce?
var name = null;
name = "Flutter";
Flutter
var name = null;
name = "Flutter";
ANo error, name becomes a String
BSyntax error due to missing type declaration
CRuntime error when assigning String to null
DA compile-time error because type is inferred as Null
Attempts:
2 left
💡 Hint
Think about what type Dart infers when initialized with null.
🧠 Conceptual
expert
2:00remaining
Why use explicit types instead of var in Flutter?
Which reason best explains why you might prefer explicit types over var in Flutter app variables?
AExplicit types improve code readability and catch type errors early
BExplicit types make the app run faster at runtime
CUsing <code>var</code> disables null safety features
DExplicit types reduce the app size significantly
Attempts:
2 left
💡 Hint
Think about how explicit types help developers understand code.