Top 10 Dart (Flutter) scenario questions
Try each one yourself first, then open the model answer.
1. Calling setState after leaving a screen throws an error. What do you do?
Show answerHide answer
Check the mounted property after awaits, and cancel timers and subscriptions in dispose.
2. Scrolling a long list is janky. How would you improve it?
Show answerHide answer
Build items lazily with ListView.builder, use const widgets, avoid heavy work in build, and cache images at the right size.
3. A FutureBuilder refetches data on every rebuild. Why?
Show answerHide answer
The future is created inside build. Create it once, for example in initState, and pass the stored future.
4. Parsing a very large JSON response freezes the UI. What can you do?
Show answerHide answer
Move the work to another isolate, for example with Isolate.run or compute.
5. The whole screen rebuilds when one counter changes. How do you narrow it?
Show answerHide answer
Move state closer to where it is used and rebuild only the dependent widgets with builders or a state management library's selectors.
6. Items in a reorderable list keep the wrong state after moving. What is missing?
Show answerHide answer
Stable keys, such as ValueKey with the item's id.
7. What is the difference between final and const in a widget you are optimising?
Show answerHide answer
final is set once at runtime. const is a compile-time constant, so identical const widgets can be reused and skipped during rebuilds.
8. A nullable value must be used safely. Which Dart features help?
Show answerHide answer
Sound null safety with ?, ??, null checks that promote local variables, and avoiding the ! operator unless the value is guaranteed.
9. A stream listener keeps firing after the page closes. How do you fix it?
Show answerHide answer
Store the StreamSubscription and cancel it in dispose, or use StreamBuilder which manages it.
10. The app must work offline. How would you design it?
Show answerHide answer
Cache data locally, read from the cache first, queue writes, sync when connectivity returns and define how conflicts are resolved.
