Challenge - 5 Problems
Error Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Displaying error messages in Flutter widgets
Which option correctly displays a red error message below a TextField when the input is invalid?
Flutter
TextField(
decoration: InputDecoration(
labelText: 'Email',
errorText: isValid ? null : 'Invalid email address',
),
)Attempts:
2 left
💡 Hint
The errorText should be null when there is no error to hide the message.
✗ Incorrect
Option A correctly sets errorText to null when input is valid, so no error message shows. When invalid, it shows the red error message below the TextField. Other options either show error always or use wrong types.
❓ lifecycle
intermediate1:30remaining
Handling error state updates in Flutter StatefulWidget
In a StatefulWidget, which method should you call to update the UI after setting an error message string in the state?
Flutter
setState(() {
errorMessage = 'Network error';
});Attempts:
2 left
💡 Hint
Flutter uses a special method to notify the framework about state changes.
✗ Incorrect
Only setState is the correct Flutter method to update the UI after changing state variables. Other methods do not exist in Flutter.
🔧 Debug
advanced2:00remaining
Identifying error in Flutter error display code
What error will this Flutter code cause?
TextField(
decoration: InputDecoration(
labelText: 'Username',
errorText: errorMessage,
),
)
where errorMessage is a boolean variable.
Flutter
bool errorMessage = true; TextField( decoration: InputDecoration( labelText: 'Username', errorText: errorMessage, ), )
Attempts:
2 left
💡 Hint
Check the expected type of errorText property.
✗ Incorrect
errorText must be a String or null. Passing a boolean causes a type error at runtime.
advanced
2:30remaining
Error handling during navigation in Flutter
Which option correctly shows an error dialog if navigation to a new screen fails?
Flutter
try { await Navigator.pushNamed(context, '/details'); } catch (e) { showDialog(context: context, builder: (_) => AlertDialog(title: Text('Error'), content: Text('Failed to open screen'))); }
Attempts:
2 left
💡 Hint
Use try-catch with async-await for error handling in Flutter navigation.
✗ Incorrect
Option C uses try-catch with await correctly. Option C and C use catchError or then with onError but Navigator.pushNamed returns a Future, so catchError works but only if awaited or returned. Option C uses a non-existent onError method.
🧠 Conceptual
expert3:00remaining
Best practice for error display patterns in Flutter apps
Which approach is best to show error messages consistently across multiple screens in a Flutter app?
Attempts:
2 left
💡 Hint
Think about code reuse and consistent UI design.
✗ Incorrect
Creating a reusable ErrorDisplay widget ensures consistent look and behavior for errors across the app. Writing separate code duplicates effort and risks inconsistency. Printing errors to console is not user-friendly. Ignoring errors harms user experience.