This app shows a spinner for 3 seconds to simulate loading. Then it shows a success message. You can change hasError to true to see the error message instead.
Every branch must return a widget; missing return causes error.
Final Answer:
Missing return before CircularProgressIndicator() -> Option A
Quick Check:
All branches must return widgets [OK]
Hint: Always return widgets in build method branches [OK]
Common Mistakes:
Forgetting return keyword before widgets
Confusing variable names
Thinking else if is wrong here
5. You want to show a loading spinner, then an error message if loading fails, or content if successful. Which Flutter widget structure correctly handles this with booleans isLoading and hasError?
hard
A. if (isLoading) return CircularProgressIndicator(); else if (hasError) return Text('Error'); else return Text('Content');
B. if (hasError) return Text('Error'); else if (isLoading) return CircularProgressIndicator(); else return Text('Content');
C. if (isLoading && hasError) return CircularProgressIndicator(); else return Text('Content');
D. if (hasError) return CircularProgressIndicator(); else if (isLoading) return Text('Loading'); else return Text('Content');
Solution
Step 1: Prioritize error over loading
If there is an error, show error message first before loading or content.
Step 2: Show loading only if no error and loading is true
Then show spinner if loading is true and no error.
Step 3: Show content if no error and not loading
Finally, show content when no error and loading is false.
Final Answer:
if (hasError) return Text('Error'); else if (isLoading) return CircularProgressIndicator(); else return Text('Content'); -> Option B
Quick Check:
Error first, then loading, then content [OK]
Hint: Show error before loading, loading before content [OK]
Common Mistakes:
Showing loading before error
Combining error and loading in one condition
Using wrong widgets for states
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.