Complete the code to show a simple error message using Flutter's Text widget.
return Scaffold( body: Center( child: Text([1]), ), );
The Text widget requires a string inside quotes to display text. So, "Error occurred!" is correct.
Complete the code to display an error icon before the error message.
return Scaffold( body: Center( child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon([1]), SizedBox(width: 8), Text('Error loading data'), ], ), ), );
Icons.error shows a standard error icon, which fits the error message context.
Fix the error in the code to show a red colored error message.
return Scaffold( body: Center( child: Text( 'Failed to load', style: TextStyle(color: [1]), ), ), );
Colors.red is the correct way to specify red color in Flutter's Color class.
Fill both blanks to create a reusable error widget with a red icon and message.
Widget errorDisplay() {
return Row(
children: [
Icon([1], color: Colors.red),
SizedBox(width: 5),
Text([2], style: TextStyle(color: Colors.red)),
],
);
}Icons.error and a red error message string create a consistent error display.
Fill all three blanks to create an error alert with icon, message, and a retry button.
return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon([1], size: 48, color: Colors.red), Text([2], style: TextStyle(color: Colors.red, fontSize: 18)), ElevatedButton( onPressed: [3], child: Text('Retry'), ), ], );
Icons.error_outline shows an error icon, the message explains the error, and the button triggers a retry action (here a print statement for demo).