Challenge - 5 Problems
Dart Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output of this Dart code snippet?
Consider the following Dart code:
What will be printed to the console?
void main() {
var list = [1, 2, 3];
var doubled = list.map((x) => x * 2).toList();
print(doubled);
}What will be printed to the console?
Flutter
void main() { var list = [1, 2, 3]; var doubled = list.map((x) => x * 2).toList(); print(doubled); }
Attempts:
2 left
💡 Hint
The map function applies the given function to each element of the list.
✗ Incorrect
The map function multiplies each element by 2, so the list [1, 2, 3] becomes [2, 4, 6].
❓ ui_behavior
intermediate2:00remaining
What happens when this Flutter widget is tapped?
Given this Flutter widget code:
What will happen when the blue container is tapped?
GestureDetector(
onTap: () {
print('Tapped!');
},
child: Container(
width: 100,
height: 50,
color: Colors.blue,
),
)What will happen when the blue container is tapped?
Flutter
GestureDetector(
onTap: () {
print('Tapped!');
},
child: Container(
width: 100,
height: 50,
color: Colors.blue,
),
)Attempts:
2 left
💡 Hint
onTap prints a message but does not change the UI by itself.
✗ Incorrect
The onTap callback prints 'Tapped!' to the console. The container color remains blue because no state change occurs.
❓ lifecycle
advanced2:00remaining
Which method is called first in a StatefulWidget lifecycle?
In Flutter, when a StatefulWidget is inserted into the widget tree, which lifecycle method is called first in its State object?
Attempts:
2 left
💡 Hint
This method is called once when the State object is created.
✗ Incorrect
initState() is called once when the State object is first created, before build().
advanced
2:00remaining
What is the result of this Flutter navigation code?
Given this Flutter code snippet:
What will happen after these two calls execute sequentially?
Navigator.push( context, MaterialPageRoute(builder: (context) => SecondScreen()), ); Navigator.pop(context);
What will happen after these two calls execute sequentially?
Flutter
Navigator.push( context, MaterialPageRoute(builder: (context) => SecondScreen()), ); Navigator.pop(context);
Attempts:
2 left
💡 Hint
push adds a new screen, pop removes the current screen.
✗ Incorrect
push navigates to SecondScreen, then pop immediately returns to the previous screen, so the user sees no lasting navigation change.
🔧 Debug
expert2:00remaining
What error does this Dart code produce?
Analyze this Dart code:
What error will this code cause at runtime?
void main() {
int? a = null;
int b = a! + 5;
print(b);
}What error will this code cause at runtime?
Flutter
void main() { int? a = null; int b = a! + 5; print(b); }
Attempts:
2 left
💡 Hint
The ! operator asserts the value is not null at runtime.
✗ Incorrect
Using ! on a null value causes a runtime exception: Null check operator used on a null value.