0
0
Fluttermobile~20 mins

Dart programming language overview in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dart Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output of this Dart code snippet?
Consider the following Dart code:
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);
}
A[2, 4, 6]
B[1, 2, 3]
C[1, 4, 9]
DError: map is not a function
Attempts:
2 left
💡 Hint
The map function applies the given function to each element of the list.
ui_behavior
intermediate
2:00remaining
What happens when this Flutter widget is tapped?
Given this Flutter widget code:
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,
  ),
)
AThe console prints 'Tapped!' and the container color changes to red.
BNothing happens because onTap is not set correctly.
CThe console prints 'Tapped!' but the container color stays blue.
DThe app crashes due to missing MaterialApp widget.
Attempts:
2 left
💡 Hint
onTap prints a message but does not change the UI by itself.
lifecycle
advanced
2: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?
AinitState()
Bbuild()
CdidChangeDependencies()
Ddispose()
Attempts:
2 left
💡 Hint
This method is called once when the State object is created.
navigation
advanced
2:00remaining
What is the result of this Flutter navigation code?
Given this Flutter code snippet:
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);
AThe app crashes due to calling pop immediately after push.
BThe app navigates to SecondScreen and then immediately returns to the previous screen.
CThe app stays on the current screen without navigation.
DThe app navigates to SecondScreen and stays there.
Attempts:
2 left
💡 Hint
push adds a new screen, pop removes the current screen.
🔧 Debug
expert
2:00remaining
What error does this Dart code produce?
Analyze this Dart code:
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);
}
ANo error; prints 5
BSyntax error: Unexpected token '!'
CCompile-time error: Cannot assign null to non-nullable int
DRuntime error: Null check operator used on a null value
Attempts:
2 left
💡 Hint
The ! operator asserts the value is not null at runtime.