Flutter Performance Flutter Interview Questions
8 questions
Why should you use const widgets in Flutter?
A `const` widget is created once at compile time and reused across rebuilds — Flutter can skip rebuilding it entirely because it knows the instance can never change.
How do you avoid unnecessary widget rebuilds in Flutter?
Scope state narrowly (so only the widgets that depend on it rebuild), use `const` constructors wherever possible, and split large build methods into smaller widgets so a change in one part doesn't force the whole tree to re-render.
How do you optimize long lists in Flutter?
Use `ListView.builder` (or `SliverList`) instead of building all items eagerly, always provide `key`s for items that can reorder, and avoid expensive work inside the `itemBuilder`.
How does Flutter manage memory, and how do you avoid leaks?
Dart uses automatic garbage collection, so you don't free memory manually — leaks in Flutter almost always come from long-lived objects (controllers, streams, listeners) holding references that prevent disposed widgets' resources from being collected.
How do you use Flutter DevTools to diagnose a performance problem?
Run the app in profile mode (not debug), open the Performance/CPU Profiler view in DevTools, record a timeline while reproducing the janky interaction, and look for frames exceeding the 16ms (60fps) budget, then inspect which widget's build/layout/paint is taking too long.
What does RepaintBoundary do and when should you use it?
RepaintBoundary isolates its child into a separate compositing layer, so repainting that subtree doesn't force everything around it to repaint too — useful for expensive-to-paint widgets that change independently, but overusing it wastes memory on unnecessary layers.
How does Flutter cache images, and what does precacheImage do?
Flutter's ImageCache automatically caches decoded images in memory by default so repeated use of the same image doesn't re-decode it; precacheImage() lets you proactively load and decode an image into that cache before it's actually displayed, avoiding a visible pop-in.
What's the difference between Flutter's debug, profile, and release build modes?
Debug mode includes assertions, hot reload, and debugging info at the cost of performance; profile mode strips debug overhead but keeps enough tooling support to profile performance accurately; release mode is fully optimized and stripped for production.