Skip to content
Tutorials Center
My learning

Topics

Lesson 72 of 73 ยท Practice and review

Flutter Interview Questions

Flutter interview questions with clear answers: widgets, the three trees, keys, state management, async Dart, performance and app architecture, with runnable examples.

A Flutter interview checks whether you hold a correct mental model, not whether you can recite the widget catalog. Interviewers want to hear why a widget is cheap, what setState really does, why a list needs keys, and how you would structure an app that has to live for years. The questions below are grouped by topic. Each answer is short enough to say aloud in under a minute, and links to the lesson that explains it fully.

How to use the page: read the question, answer it aloud in your own words, then compare. Do not memorize sentences; the bold phrases are the points an interviewer listens for. Be ready for the follow-up "why?" and "what would break if...?".

Real vs stand-in. The Dart snippets are real Flutter and read-only on this site. Two JavaScript stand-ins let you run the ideas behind the trickiest answers (dirty-marking and keyed reconciliation). They illustrate the mechanism; they are not Flutter's actual code.

What interviewers probe

Trees Widget, Element, RenderObject.
State Where it lives and who rebuilds.
Async Futures, streams, isolates.
Architecture Layers you can test.
1 / 2

Fundamentals

1. What is Flutter, and how does it differ from React Native?

Flutter is a UI toolkit that compiles Dart to native code and draws every pixel itself with its own rendering engine (Impeller on modern platforms, Skia as the older engine). It does not wrap native buttons. React Native runs JavaScript and maps components to native platform views. The Flutter consequence: identical look on every platform and no bridge to platform widgets, but your UI does not automatically pick up native widget changes. See What is Flutter?.

2. Why Dart?

Dart supports ahead-of-time compilation for fast release builds and just-in-time compilation with stateful hot reload in development. It has sound null safety, async/await, and an object model that suits UI trees. The same language runs the UI and the tooling.

3. What is the difference between hot reload and hot restart?

Hot reload injects changed code into the running VM and rebuilds the widget tree, keeping state. Hot restart restarts the app and resets all state. Changes to main, global initializers or enum shapes usually need a restart. See setup.

4. What is the difference between final and const?

final is assigned once, at runtime. const is a compile-time constant: the value is known when compiling, and identical const objects are canonicalized (one shared instance). const widgets let Flutter skip rebuilding them. See Dart basics.

5. Explain null safety in one minute.

Types are non-nullable by default; String? can hold null. Flow analysis promotes a nullable variable to non-null after a check. You use ?., ??, ! (an assertion that throws if wrong) and late (initialize later, error if read too early). The compiler stops null errors before the app runs. See null safety.

Widgets and the three trees

6. What is a widget?

A widget is an immutable description of part of the UI: configuration, not a pixel container. Widgets are cheap to create and are thrown away on every rebuild. See Everything is a widget.

7. StatelessWidget vs StatefulWidget?

A StatelessWidget builds only from its constructor arguments and inherited data. A StatefulWidget creates a separate long-lived State object that holds mutable data and survives rebuilds of the widget. The widget itself is still immutable. See StatefulWidget and setState.

8. What are the three trees?

  • Widget tree: the immutable configuration you write.
  • Element tree: the live instances that hold position and state, created from widgets. Elements are reused when the new widget has the same type and key.
  • RenderObject tree: objects that perform layout, painting and hit testing.

Rebuilding creates new widgets, but the element tree is updated in place and render objects are only touched if their properties changed. That is why rebuilds are cheap. See Widget, Element and RenderObject trees.

9. What does setState do?

It runs your callback and marks the element dirty, so build runs again in the next frame. It does not rebuild immediately and does not magically detect changes: if you change data without setState, nothing redraws.

JS Stand-in: dirty marking and a frame

Press Run (or Ctrl + Enter) to see the console output here.

No output.

10. When do you need keys?

When widgets of the same type can change order, be inserted or removed in a collection, and carry state (checkbox, text field, animation). Without keys, Flutter matches by position and type, so state sticks to the slot, not to the item. ValueKey uses an identifying value, ObjectKey an object identity, GlobalKey finds a state from elsewhere (use sparingly). See keys and identity.

JS Stand-in: reconciliation by position vs by key

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Without keys, "Beta" inherits Alpha's typed text; with keys, state follows the item.

11. What is BuildContext?

A handle to a widget's location in the tree (technically its Element). Lookups like Theme.of(context) walk up from that location. Using a context from a different place (such as the MaterialApp level for a Scaffold) gives the wrong ancestors. See BuildContext and InheritedWidget.

12. What is an InheritedWidget?

A widget that exposes data to all descendants and rebuilds only those that depend on it through dependOnInheritedWidgetOfExactType. Theme, MediaQuery and Provider are built on this idea.

Layout

13. Explain Flutter's layout rule.

Constraints go down, sizes go up, parents set positions. A parent passes min/max width and height to the child; the child chooses a size within them and reports it; the parent places it. A child cannot pick its own position and cannot exceed its constraints. See constraints and layout.

14. What causes "unbounded height" and "RenderFlex overflow"?

Unbounded errors: a scrollable (or something needing a size) sits inside a parent that offers infinite space, such as a ListView in a Column. Overflow: children need more space than is available. Fixes: Expanded/Flexible, SizedBox, scrolling, or Wrap. See common mistakes.

15. Expanded vs Flexible?

Expanded is Flexible with fit: FlexFit.tight: the child must fill its share. Flexible defaults to loose: the child may be smaller. Both divide leftover space by flex factor. See Row, Column and Flex.

16. Why use ListView.builder?

It builds children lazily, only those near the viewport, and recycles them as you scroll. A plain ListView(children: [...]) builds all of them up front. See ListView, GridView and slivers.

State management

17. Ephemeral state vs app state?

Ephemeral (UI) state belongs to one widget (selected tab, text in a field) and fits setState. App state is shared or must outlive a screen (login, cart, settings) and needs lifting up or a state-management solution. See lifting state up.

18. How does Provider work, and watch vs read vs select?

Provider puts an object (often a ChangeNotifier) above the widgets that need it, using InheritedWidget underneath. watch subscribes and rebuilds on every change, read fetches once without subscribing (use in callbacks), select rebuilds only when one selected value changes. See Provider.

19. Riverpod vs Provider vs BLoC?

Provider is simple and widely known. Riverpod removes the dependency on BuildContext, supports compile-safe providers, async providers, family, autodispose and easy overrides in tests. BLoC/Cubit models state as streams of immutable states with explicit events, which scales well in big teams and is easy to test, at the cost of boilerplate. Choose by team size and complexity, not fashion. See Riverpod, BLoC and choosing.

20. Why prefer immutable state?

A new object means a clear "something changed" signal (!=), safe sharing, easier debugging and testing. Mutating a list in place requires manual notification and invites bugs.

Async Dart

21. How does Dart handle concurrency?

Dart code runs on one thread per isolate, with an event loop that processes a microtask queue and an event queue. Future and async/await do not create threads; they schedule continuations. Isolates have separate memory and talk by messages, so use them (Isolate.run, compute) for heavy CPU work such as parsing a huge JSON. See Futures, async/await and streams.

22. Future vs Stream?

A Future delivers one value (or error) later. A Stream delivers zero or more values over time; it can be single-subscription or broadcast. In UI, FutureBuilder and StreamBuilder turn them into widgets. See FutureBuilder and StreamBuilder.

23. Why must you not call an API inside build?

build may run many times (animations, parent rebuilds, keyboard changes), and it must be pure and fast. Start requests in initState, an event handler, or a state layer.

Performance

24. How do you keep a Flutter app smooth?

Stay inside the frame budget (about 16 ms at 60 Hz, 8 ms at 120 Hz). Use const widgets, narrow rebuilds into small widgets, use lazy lists, avoid work in build, move heavy computation to isolates, avoid Opacity and clipping on big animated areas (use AnimatedOpacity or FadeTransition), and profile in profile mode with DevTools. See performance and DevTools.

25. Why profile in profile mode, not debug?

Debug builds run in JIT with assertions and are much slower, so numbers mislead. Profile mode is close to release but keeps profiling hooks.

Architecture and quality

26. How would you structure a medium-sized app?

Layers: UI (widgets) โ†’ state/view-model โ†’ repository โ†’ data sources (HTTP client, database). Dependencies point inward, repositories hide where data comes from, and dependency injection (Provider, Riverpod, get_it) lets tests swap fakes. See choosing state management and architecture.

27. Unit vs widget vs integration tests?

Unit tests check plain Dart logic quickly. Widget tests build a widget in a test environment (testWidgets, pump, finders) without a device. Integration tests run the full app on a device or emulator. The usual shape is many unit and widget tests, fewer integration tests. See testing.

28. How do you handle platform-specific code?

With platform channels (MethodChannel, EventChannel), Pigeon for typed channels, or FFI for C libraries, usually packaged as a plugin. See platform channels.

29. How do you store a token securely?

Never in SharedPreferences or in the source code. Use the platform keystore through a secure-storage plugin, keep tokens short-lived, and assume anything shipped in the app binary can be extracted. See security.

Interview questions, part 2

30. What is the difference between WidgetsApp, MaterialApp and CupertinoApp?

WidgetsApp is the bare foundation: it sets up the Navigator, localization, MediaQuery and the title, but gives you no design language, no Theme and no Material widgets. MaterialApp builds on it and adds Material theming, ScaffoldMessenger (snack bars), Material page transitions and default text styles. CupertinoApp does the same for the iOS look. You pick one at the root; you can mix Material and Cupertino widgets inside, but widgets like Scaffold need a MaterialApp (or at least a Material ancestor) above them.

31. What is the difference between push, pushReplacement and pushAndRemoveUntil?

push adds a route on top, and Back returns to the one below. pushReplacement swaps the current route for a new one, so the old screen is gone and Back skips it (a splash screen to home). pushAndRemoveUntil pushes a route and pops everything below it until a predicate returns true; (route) => false clears the whole stack (after login or logout). The named versions (pushNamed, pushReplacementNamed, pushNamedAndRemoveUntil) do the same by route name. Details are in Navigator and Routes, and declarative routing in go_router.

32. What are Flutter's build modes?

Debug uses JIT compilation, asserts, hot reload and the debugger, and is slow on purpose. Profile is compiled ahead of time, close to release speed, and keeps tracing hooks for DevTools; test performance here, on a real device. Release is AOT-compiled and optimized, with asserts stripped, no debugger and the smallest size. A kDebugMode or kReleaseMode constant lets you branch on them, and assert(...) bodies only run in debug (performance and DevTools).

33. Flutter versus React Native: what are the real differences?

Rendering: Flutter draws its own widgets on a canvas with its own engine, so the UI is identical across platforms and does not depend on native widget versions; React Native renders native views, which look native by default but can differ per platform. Language: Dart (AOT and JIT) versus JavaScript or TypeScript. Architecture: Flutter calls native code through platform channels or FFI; React Native uses its JavaScript interface to native modules. Ecosystem: React Native taps the large npm and web-developer pool; Flutter has a smaller but curated package set and strong first-party tooling. Neither is universally better: team skills, existing code and the need for a platform-native look decide.

34. What does setState actually do?

It runs your callback synchronously, marks the State's element dirty, and schedules a rebuild for the next frame. It does not rebuild immediately, and several calls in one frame cause one rebuild. Calling it after dispose is an error, so check mounted after any await (StatefulWidget and setState).

35. What is an Isolate, and when do you need one?

An isolate is Dart's unit of concurrency: its own memory heap and event loop, communicating only by messages, so there are no shared-memory data races. The UI runs on the main isolate; heavy work such as parsing a huge JSON document or compressing an image blocks it and drops frames. Use compute() or Isolate.run() to move such work off the main isolate. Waiting for I/O does not need an isolate: await does not block the event loop (Futures, async/await and Streams).

36. What is the difference between a StatelessWidget and a StatefulWidget, and when would you pick each?

A stateless widget has no mutable state of its own: given the same inputs it builds the same UI. A stateful widget pairs an immutable widget with a long-lived State object that holds mutable data and lifecycle methods (initState, didUpdateWidget, dispose). Prefer stateless widgets, and add state only for data that belongs to that widget alone (an animation controller, a text controller, a selected tab).

37. How do Keys help, and when are they necessary?

A key lets the framework match an old element with a new widget after a reorder or removal. Without keys in a list of stateful items, state can stay at a position while the data moves. Use ValueKey for data ids, ObjectKey for objects, UniqueKey to force a new element, and GlobalKey sparingly to reach a state from far away (Keys and widget identity).

38. How do you reduce app size?

Build with --release and split per ABI on Android (or ship an app bundle), remove unused packages and assets, compress images and prefer vector graphics, avoid shipping unused font weights, and use --analyze-size to see what is large. Deferred components can load rarely used features on demand (publishing).

39. How do you handle different screen sizes?

Use constraints instead of fixed numbers: Flexible, Expanded, LayoutBuilder and MediaQuery.sizeOf for breakpoints, ConstrainedBox for maximum widths, and adaptive widgets such as NavigationRail on wide screens (Responsive and adaptive layouts). Test on small phones, tablets and a resizable desktop window, with large text sizes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does setState actually do?

    Dirty marking schedules a rebuild; it does not detect changes or run build synchronously.
  2. 2. Why are widget rebuilds cheap?

    Only configuration objects are recreated; the element tree is updated in place.
  3. 3. When are keys required for correct behavior?

    Without keys, state is matched by position, so it sticks to the wrong item after a reorder.
  4. 4. Which tool moves heavy CPU work off the UI thread?

    async/await stays on the same isolate; only a separate isolate runs in parallel.

Summary

  • Know the three trees, why widgets are cheap, and what setState does.
  • Explain the layout rule and fix overflow and unbounded errors.
  • Match state to its scope, and justify your state-management choice.
  • Understand the event loop, futures, streams and isolates.
  • Keep build pure, profile in profile mode, and layer the architecture.

Next: Flutter and Dart Cheat Sheet