Component - Loading and error states
This UI component shows how an app displays a loading spinner while waiting for data and an error message if loading fails. It helps users understand what is happening and keeps the app friendly and clear.
This UI component shows how an app displays a loading spinner while waiting for data and an error message if loading fails. It helps users understand what is happening and keeps the app friendly and clear.
Scaffold
├── AppBar
└── Center
└── ConditionalWidget
├── CircularProgressIndicator (if loading)
├── Text (if error)
└── Text (if data loaded)bool isLoading = true;
Widget build(BuildContext context) {
if (isLoading) {
return CircularProgressIndicator();
} else {
return Text('Data loaded');
}
}bool hasError = false;
bool isLoading = true;
Widget build(BuildContext context) {
if (hasError) {
return Text('Error occurred');
} else if (isLoading) {
CircularProgressIndicator();
} else {
return Text('Content loaded');
}
}isLoading and hasError?Pass the test and this pattern moves unknown