0
0
Fluttermobile~20 mins

Error display patterns in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Error Display Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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',
  ),
)
ATextField(decoration: InputDecoration(labelText: 'Email', errorText: isValid ? null : 'Invalid email address'))
BTextField(decoration: InputDecoration(labelText: 'Email', errorText: isValid))
CTextField(decoration: InputDecoration(labelText: 'Email', errorText: 'Invalid email address'))
DTextField(decoration: InputDecoration(labelText: 'Email', errorText: isValid ? 'Error' : null))
Attempts:
2 left
💡 Hint
The errorText should be null when there is no error to hide the message.
lifecycle
intermediate
1: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';
});
Arefresh(() { errorMessage = 'Network error'; });
BsetState(() { errorMessage = 'Network error'; });
CupdateUI(() { errorMessage = 'Network error'; });
Drebuild(() { errorMessage = 'Network error'; });
Attempts:
2 left
💡 Hint
Flutter uses a special method to notify the framework about state changes.
🔧 Debug
advanced
2: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,
  ),
)
ARuntime error: NullPointerException
BNo error, displays error message 'true'
CSyntaxError: missing quotes around errorMessage
DTypeError: errorText expects a String or null, but got bool
Attempts:
2 left
💡 Hint
Check the expected type of errorText property.
navigation
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')));
}
ANavigator.pushNamed(context, '/details').then((_) {}, onError: (e) => showDialog(context: context, builder: (_) => AlertDialog(title: Text('Error'), content: Text('Failed to open screen'))));
BNavigator.pushNamed(context, '/details').catchError((e) => showDialog(context: context, builder: (_) => AlertDialog(title: Text('Error'), content: Text('Failed to open screen'))));
Ctry { await Navigator.pushNamed(context, '/details'); } catch (e) { showDialog(context: context, builder: (_) => AlertDialog(title: Text('Error'), content: Text('Failed to open screen'))); }
DNavigator.pushNamed(context, '/details').onError((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.
🧠 Conceptual
expert
3: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?
ACreate a reusable ErrorDisplay widget and use it wherever errors need to be shown
BWrite separate error message code in each screen widget manually
CUse print statements to show errors in the console only
DIgnore errors and let the app crash to detect issues
Attempts:
2 left
💡 Hint
Think about code reuse and consistent UI design.