0
0
Fluttermobile~20 mins

Loading and error states in Flutter - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Loading and Error Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Loading 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'),
    );
  }
}
AA spinning circular progress indicator is shown.
BA blank screen is shown.
CThe text 'Content Loaded' is shown.
DAn error message is shown.
Attempts:
2 left
💡 Hint
Check what widget is returned when isLoading is true.
ui_behavior
intermediate
2:00remaining
Error 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'),
    );
  }
}
ANothing is shown.
BThe text 'Data loaded successfully' is shown.
CA loading spinner is shown.
DThe text 'Failed to load data' is shown.
Attempts:
2 left
💡 Hint
Look at the condition that controls which text is shown.
lifecycle
advanced
2:30remaining
State 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),
    );
  }
}
AThe loading spinner will never disappear and data will not show.
BThe data text will appear immediately without loading spinner.
CThe app will crash with an error.
DThe loading spinner will disappear but data text will be empty.
Attempts:
2 left
💡 Hint
Think about what triggers the UI to update in Flutter stateful widgets.
navigation
advanced
2:30remaining
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
  }
}
ANavigator.pushReplacement(context, MaterialPageRoute(builder: (_) => ErrorScreen()));
BNavigator.pop(context, MaterialPageRoute(builder: (_) => ErrorScreen()));
CNavigator.push(context, MaterialPageRoute(builder: (_) => ErrorScreen()));
DNavigator.pushNamed(context, '/error');
Attempts:
2 left
💡 Hint
Use navigation to add a new screen on top of the current one.
🧠 Conceptual
expert
3:00remaining
Best Practice for Loading and Error States
Which approach best improves user experience when handling loading and error states in a Flutter app?
AShow a blank screen until data loads, then show content or crash on error.
BShow a loading spinner during data fetch, then show content or an error message with retry option.
CShow content immediately and update silently without any loading or error indicators.
DShow an error message first, then load data in the background without user feedback.
Attempts:
2 left
💡 Hint
Think about clear communication and giving users control.