Challenge - 5 Problems
Loading and Error Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediateLoading Indicator Visibility
What will be displayed on the screen when the
isLoading variable is true in this Flutter widget?Flutter
class LoadingWidget extends StatelessWidget { final bool isLoading; LoadingWidget({required this.isLoading}); @override Widget build(BuildContext context) { return Center( child: isLoading ? CircularProgressIndicator() : Text('Content Loaded'), ); } }
Attempts:
2 left
💡 Hint
Check what widget is returned when
isLoading is true.✗ Incorrect
When
isLoading is true, the widget shows a CircularProgressIndicator, which is a spinning circle indicating loading.❓ ui_behavior
intermediateError Message Display
Given this Flutter widget, what text will appear if
hasError is true?Flutter
class ErrorWidgetExample extends StatelessWidget { final bool hasError; ErrorWidgetExample({required this.hasError}); @override Widget build(BuildContext context) { return Center( child: hasError ? Text('Failed to load data') : Text('Data loaded successfully'), ); } }
Attempts:
2 left
💡 Hint
Look at the condition that controls which text is shown.
✗ Incorrect
When
hasError is true, the widget shows the error message text.❓ lifecycle
advancedState Update After Async Load
In this Flutter stateful widget, what happens if
setState is not called after data is loaded asynchronously?Flutter
class DataLoader extends StatefulWidget { @override _DataLoaderState createState() => _DataLoaderState(); } class _DataLoaderState extends State<DataLoader> { bool isLoading = true; String data = ''; @override void initState() { super.initState(); loadData(); } Future<void> loadData() async { await Future.delayed(Duration(seconds: 2)); data = 'Loaded Data'; // Missing setState here } @override Widget build(BuildContext context) { return Center( child: isLoading ? CircularProgressIndicator() : Text(data), ); } }
Attempts:
2 left
💡 Hint
Think about what triggers the UI to update in Flutter stateful widgets.
✗ Incorrect
Without calling
setState, Flutter does not know the state changed, so the UI stays showing the loading spinner.advanced
Error Screen Navigation
Which code snippet correctly navigates to an error screen when an error occurs during data loading in Flutter?
Flutter
Future<void> loadData(BuildContext context) async { try { await fetchData(); } catch (e) { // Navigate to error screen } }
Attempts:
2 left
💡 Hint
Use navigation to add a new screen on top of the current one.
✗ Incorrect
Using
Navigator.push adds the error screen on top, showing it to the user.🧠 Conceptual
expertBest Practice for Loading and Error States
Which approach best improves user experience when handling loading and error states in a Flutter app?
Attempts:
2 left
💡 Hint
Think about clear communication and giving users control.
✗ Incorrect
Showing a spinner during loading and an error message with retry improves clarity and user control.
