Flutter Interview Questions & Answers
This set covers 88 Flutter interview questions with point-wise answers, written from a working mobile developer's point of view. Each answer is concise and structured the way you should speak in an interview.
Flutter & Dart Fundamentals
1. What is Flutter?
- Google's open-source UI toolkit for building apps from a single codebase.
- It targets iOS, Android, web, desktop, and embedded.
- It renders its own widgets using the Skia/Impeller engine, not native controls.
- It uses the Dart language and a reactive, declarative UI model.
2. Why does Flutter use Dart?
- Dart supports both JIT (fast hot reload) and AOT (fast release) compilation.
- It is object-oriented with strong typing and null safety.
- Its isolate model avoids shared-memory threading issues.
- It was designed to make declarative UI ergonomic.
3. What is a widget in Flutter?
- The basic building block describing a part of the UI.
- Everything is a widget — layout, text, padding, even the app itself.
- Widgets are immutable descriptions, rebuilt on change.
- They compose into a tree to form the interface.
4. What is the difference between StatelessWidget and StatefulWidget?
- StatelessWidget has no mutable state and renders from its inputs.
- StatefulWidget holds state that can change over the widget's life.
- Stateful widgets pair with a
Stateobject that persists across rebuilds. - Use stateless when nothing changes internally; stateful when it does.
5. What is the widget tree?
- The hierarchy of widgets describing the UI.
- Parent widgets contain and configure children.
- Flutter walks this tree to build the UI each frame as needed.
- It is the declarative description, not the rendered pixels.
6. What are the three trees in Flutter?
- Widget tree: immutable configuration.
- Element tree: mutable instances linking widgets to render objects.
- Render tree: handles layout, painting, and hit testing.
- Elements let Flutter reuse render objects efficiently across rebuilds.
7. What is the build method?
- It returns the widget subtree describing the UI.
- Flutter calls it whenever the widget needs to render.
- It should be pure and fast, with no side effects.
- It can run frequently, so avoid expensive work inside it.
8. What is BuildContext?
- A handle to a widget's location in the element tree.
- It lets you look up inherited widgets, theme, and media query.
- Each widget gets its own context in
build. - Using the wrong context (e.g. across async gaps) is a common bug.
9. What is hot reload and how does it differ from hot restart?
- Hot reload injects updated code and rebuilds the widget tree, keeping state.
- Hot restart resets the app and clears all state.
- Hot reload is faster for UI tweaks.
- Use hot restart when state or app initialisation changes.
10. What is null safety in Dart?
- Types are non-nullable by default; add
?to allow null. - It prevents null-dereference crashes at compile time.
- The
latekeyword defers initialisation of non-null variables. - It makes nullability explicit and intentional.
11. What is the difference between final and const in Dart?
finalis set once at runtime and cannot be reassigned.constis a compile-time constant.constwidgets are canonicalised and skip rebuilds.- Use
constfor fixed values known at compile time.
12. Why are const constructors important for performance?
- Const widgets are created once and reused.
- Flutter can skip rebuilding and repainting them.
- They reduce garbage collection pressure.
- Marking static subtrees
constis an easy optimisation.
13. What is the difference between var, dynamic, and Object?
varinfers a fixed type from the initial value.dynamicdisables static type checking.Objectis the base type but keeps type safety.- Prefer
var/explicit types; avoiddynamicunless necessary.
14. What are named and positional parameters in Dart?
- Positional parameters are passed by order.
- Named parameters are passed by label, improving readability.
- Named params can be
requiredor have defaults. - Flutter widget constructors use named params heavily.
15. What are mixins in Dart?
- A way to reuse code across class hierarchies without inheritance.
- Declared with
mixinand applied withwith. - Example:
SingleTickerProviderStateMixinfor animations. - They add behaviour to multiple unrelated classes.
Widgets & Layout
16. What is the difference between Container and SizedBox?
Containercombines padding, margin, decoration, and sizing.SizedBoxonly sets a fixed width/height or adds spacing.SizedBoxis lighter when you only need dimensions.- Use
Containerwhen you need decoration or alignment too.
17. What is the difference between Row and Column?
Rowlays children out horizontally.Columnlays children out vertically.- Both use main-axis and cross-axis alignment.
- They are the core flex layout widgets.
18. What are mainAxisAlignment and crossAxisAlignment?
- Main axis is the direction the Row/Column lays out children.
- Cross axis is perpendicular to it.
mainAxisAlignmentspaces children along the main axis.crossAxisAlignmentaligns them along the cross axis.
19. What is the Expanded widget?
- It makes a child fill available space along the main axis.
- It uses a
flexfactor to share space proportionally. - It must be inside a Row, Column, or Flex.
- It prevents overflow by allocating remaining space.
20. What is the difference between Expanded and Flexible?
Expandedforces a child to fill all available space.Flexiblelets a child take up to the available space but no more.ExpandedisFlexiblewithfit: FlexFit.tight.- Use
Flexiblewhen the child should size to its content if smaller.
21. What is the difference between Stack and Column?
Columnarranges children linearly.Stackoverlays children on top of each other.Positionedplaces children precisely within a Stack.- Use Stack for overlapping UI like badges or banners.
22. How does ListView work and why use ListView.builder?
ListViewscrolls a list of children.ListView.builderlazily builds items as they scroll into view.- It is essential for long or infinite lists to save memory.
- The builder is called only for visible items.
23. What is the difference between ListView and GridView?
ListViewshows items in a single scrollable column or row.GridViewarranges items in a 2D scrollable grid.- Both have builder variants for lazy construction.
- Choose based on whether layout is linear or grid-based.
24. What is a Sliver?
- A scrollable area piece used inside a
CustomScrollView. - Slivers enable advanced effects like collapsing app bars.
- Examples:
SliverAppBar,SliverList,SliverGrid. - They give fine control over scroll behaviour.
25. What is the difference between Padding and Margin in Flutter?
- Flutter has no separate margin property; use
PaddingorContainermargin. - Padding adds space inside a widget's boundary.
- Container margin adds space outside its boundary.
- Both take
EdgeInsetsvalues.
26. What are constraints in Flutter layout?
- "Constraints go down, sizes go up, parent sets position."
- A parent passes constraints; the child picks a size within them.
- The parent then positions the child.
- Understanding this model explains most layout errors.
27. What is a LayoutBuilder?
- A widget that gives you the parent's constraints during build.
- Use it to build responsive layouts based on available space.
- It rebuilds when constraints change.
- Useful for adapting between phone and tablet sizes.
28. What is a MediaQuery?
- It exposes screen size, padding, text scale, and orientation.
- Use it for responsive sizing and safe-area awareness.
- Accessed via
MediaQuery.of(context). - It rebuilds dependents when the metrics change.
29. What is the difference between Material and Cupertino widgets?
- Material widgets follow Android's Material Design.
- Cupertino widgets follow Apple's iOS design.
- You can mix them or branch by platform.
- Both deliver platform-appropriate look and feel.
30. What is a Scaffold?
- A layout structure implementing the basic Material visual layout.
- It provides slots for app bar, body, drawer, FAB, and bottom bar.
- It handles snack bars and bottom sheets.
- It is the typical root of a screen.
State Management
31. What is state in Flutter?
- Data that can change and affects what a widget displays.
- Local (ephemeral) state lives in a widget's
State. - App (shared) state is used across many widgets.
- Choosing where state lives is a core design decision.
32. What is setState and how does it work?
- It notifies Flutter that state changed and the widget must rebuild.
- You mutate state inside its callback.
- Flutter then re-runs
buildfor that widget. - Calling it excessively or with heavy work hurts performance.
33. What is the difference between ephemeral and app state?
- Ephemeral state belongs to one widget, e.g. a toggle.
- App state is shared, e.g. logged-in user or cart.
- Ephemeral uses
setState; app state uses a management solution. - Pick the smallest scope that works.
34. What are popular state management approaches in Flutter?
- Provider, Riverpod, BLoC/Cubit, GetX, and Redux.
- They differ in boilerplate, testability, and reactivity style.
- Provider/Riverpod are common defaults.
- BLoC suits larger apps needing clear event/state separation.
35. What is the Provider package?
- A wrapper over
InheritedWidgetfor dependency injection and state. - It exposes objects down the tree and rebuilds listeners on change.
ChangeNotifierProvideris a common pairing.- It reduces boilerplate compared to raw inherited widgets.
36. What is the BLoC pattern?
- Business Logic Component separates UI from logic via streams.
- UI sends events; the BLoC emits new states.
- It promotes testability and clear unidirectional flow.
- Cubit is a simpler variant without explicit events.
37. What is the difference between BLoC and Cubit?
- BLoC maps incoming events to output states.
- Cubit exposes methods that emit states directly.
- Cubit has less boilerplate; BLoC offers more traceability.
- Both come from the same package family.
38. What is Riverpod and how does it differ from Provider?
- Riverpod is a rewrite addressing Provider's limitations.
- It is compile-safe and does not depend on
BuildContext. - Providers are global and testable in isolation.
- It supports auto-dispose and easy overrides.
39. What is a ChangeNotifier?
- A class that notifies listeners when it changes.
- Call
notifyListeners()after mutating state. - It pairs with
ChangeNotifierProvider. - Remember to dispose it to avoid leaks.
40. What is an InheritedWidget?
- A widget that efficiently propagates data down the tree.
- Descendants access it via
.of(context)and rebuild on change. - It underpins Theme, MediaQuery, and Provider.
- It is the low-level primitive for shared state.
41. How do you choose a state management solution?
- Match it to app size and team familiarity.
- Small apps:
setStateor Provider. - Larger apps: Riverpod or BLoC for structure and testability.
- Avoid mixing many approaches in one codebase.
42. What is a ValueNotifier and ValueListenableBuilder?
ValueNotifierholds a single value and notifies on change.ValueListenableBuilderrebuilds only when that value changes.- It is a lightweight, dependency-free reactive option.
- Good for isolated, simple reactive UI.
43. What is the difference between Consumer and context.watch?
- Both rebuild on provider changes.
Consumerscopes rebuilds to a small subtree via a builder.context.watchrebuilds the whole widget that calls it.- Use
Consumerto limit rebuild scope for performance.
44. How do you avoid unnecessary rebuilds?
- Use
constwidgets and split UI into small widgets. - Scope listeners with
Consumerorselect. - Avoid rebuilding large subtrees on small changes.
- Keep heavy widgets out of frequently rebuilt branches.
45. What is the key property and why does it matter?
- Keys preserve widget identity across rebuilds.
- They help Flutter match elements to the right widgets.
ValueKey/ObjectKeyidentify list items.- Wrong or missing keys cause state mix-ups in lists.
Navigation & Routing
46. How does navigation work in Flutter?
- The
Navigatormanages a stack of routes (screens). pushadds a route;popremoves the top one.- Named routes and the Router API support declarative navigation.
- It models app navigation as a stack of pages.
47. What is the difference between push and pushReplacement?
pushadds a new route above the current one.pushReplacementswaps the current route for a new one.- Replacement removes the previous screen from the stack.
- Use replacement for flows like login to home.
48. What are named routes?
- String identifiers mapped to screen builders.
- Defined in the app's
routestable. - Navigate with
pushNamed. - They centralise route definitions but are less type-safe.
49. What is the Navigator 2.0 / Router API?
- A declarative API where navigation reflects app state.
- It supports deep linking and web URL syncing better.
- It is more complex than the imperative Navigator.
- Packages like go_router simplify it.
50. What is go_router?
- A popular routing package built on the Router API.
- It offers declarative routes, deep linking, and redirects.
- It reduces Navigator 2.0 boilerplate.
- It supports nested and guarded routes.
51. How do you pass data between screens?
- Pass arguments through the route constructor or settings.
- Return data by awaiting the
pushfuture and usingpop(value). - Shared app state can carry data too.
- Prefer typed constructor arguments for safety.
52. How do you handle deep links in Flutter?
- Configure platform intent filters / universal links.
- Parse the incoming URI and route accordingly.
- go_router maps paths to screens automatically.
- Test cold-start and warm-start link handling.
Async, Networking & Data
53. What is a Future in Dart?
- It represents a value available later, like a network result.
- Handle it with
then/catchErrororasync/await. - It can complete with a value or an error.
- It is the foundation of async work in Dart.
54. What is the difference between async and await?
asyncmarks a function that returns a Future.awaitpauses until a Future completes, without blocking the thread.- Together they write asynchronous code in a linear style.
- Errors propagate as exceptions you can
try/catch.
55. What is a Stream and how does it differ from a Future?
- A Future yields a single value; a Stream yields many over time.
- Streams suit events, sockets, and live data.
- Listen with
await foror.listen(). - Streams can be single-subscription or broadcast.
56. What is a StreamBuilder?
- A widget that rebuilds as a Stream emits values.
- It exposes connection state and the latest snapshot.
- Great for live data like chat or location.
- Handle loading and error states in its builder.
57. What is a FutureBuilder?
- A widget that builds UI based on a Future's state.
- It surfaces waiting, error, and done states.
- Useful for one-shot async loads.
- Avoid recreating the Future in
buildto prevent reruns.
58. What is an isolate in Dart?
- An independent worker with its own memory and event loop.
- Isolates communicate via message passing, not shared memory.
- Use them for CPU-heavy work to avoid jank.
compute()is a simple way to run work on one.
59. Why are isolates used instead of threads?
- Dart is single-threaded per isolate, avoiding shared-memory races.
- Isolates prevent the kind of locking bugs threads cause.
- They keep the UI isolate responsive.
- Heavy parsing or computation should move off the main isolate.
60. How do you make network requests in Flutter?
- Use the
httppackage ordiofor richer features. - Await the response and parse JSON.
- Handle status codes, timeouts, and errors.
dioadds interceptors, retries, and cancellation.
61. How do you parse JSON in Flutter?
- Use
jsonDecodeto get maps, then map to model classes. - Add
fromJson/toJsonmethods to models. - Code generation (json_serializable) reduces boilerplate.
- Type your models for safety instead of using raw maps.
62. What options exist for local data persistence?
shared_preferencesfor small key-value data.- SQLite via
sqfliteordriftfor relational data. - Hive or Isar for fast NoSQL storage.
- Files or secure storage for documents and secrets.
63. How do you store sensitive data securely in Flutter?
- Use
flutter_secure_storagebacked by Keychain/Keystore. - Never store secrets in
shared_preferences. - Use HTTPS and avoid hardcoding keys.
- Encrypt local databases if they hold sensitive data.
Animations, Lifecycle & Platform
64. How do animations work in Flutter?
- An
AnimationControllerdrives values over a duration. - Widgets rebuild as the animation ticks via a
Listenable. - Tweens map the 0-1 progress to real values.
- A
TickerProvidersupplies the frame ticks.
65. What is an AnimationController?
- It produces values between bounds over time.
- It can be played forward, reversed, or repeated.
- It needs a
vsyncfrom a ticker provider. - Dispose it to free resources.
66. What is the difference between implicit and explicit animations?
- Implicit animations (e.g.
AnimatedContainer) animate property changes automatically. - Explicit animations use a controller for full control.
- Implicit is simpler; explicit handles complex sequences.
- Choose based on how much control you need.
67. What is a Tween?
- It defines a range between a begin and end value.
- It maps animation progress (0-1) to that range.
- Used for colours, sizes, offsets, and more.
- Chain with curves for non-linear motion.
68. What is a Hero animation?
- It animates a shared widget between two screens.
- Tag matching widgets with the same
tag. - Flutter flies the element during navigation.
- It creates smooth, connected transitions.
69. What are the lifecycle methods of a State object?
initStateruns once when state is created.didChangeDependenciesruns when inherited dependencies change.buildrenders the UI;didUpdateWidgethandles config changes.disposecleans up controllers and subscriptions.
70. What is the purpose of dispose?
- It releases resources before a State is destroyed.
- Cancel timers, close streams, and dispose controllers there.
- Skipping it causes memory leaks.
- It is the counterpart to
initState.
71. How do you observe app lifecycle states?
- Implement
WidgetsBindingObserverand overridedidChangeAppLifecycleState. - States include resumed, inactive, paused, and detached.
- Use them to pause work or save state in the background.
- Register and unregister the observer properly.
72. How do you call native platform code?
- Use
MethodChannelto invoke platform methods. - Send and receive messages across the Dart/native boundary.
- Use
EventChannelfor streaming native events. - Pigeon generates type-safe channel code.
73. What is a platform channel?
- A messaging bridge between Dart and native iOS/Android code.
- It serialises method calls and results.
- Use it to access platform-specific APIs.
- It enables plugins that wrap native SDKs.
Performance, Testing & Tooling
74. How do you improve Flutter app performance?
- Use
constwidgets and builder lists. - Minimise rebuild scope and avoid heavy work in
build. - Move expensive computation to isolates.
- Profile with DevTools to find real bottlenecks.
75. What causes jank and how do you fix it?
- Jank is dropped frames from work exceeding the frame budget.
- Heavy build/layout, large images, or synchronous I/O cause it.
- Offload work, cache, and reduce overdraw.
- Use the performance overlay to spot slow frames.
76. What is Flutter DevTools?
- A suite for debugging and profiling Flutter apps.
- It includes a widget inspector, timeline, and memory tools.
- It helps find rebuilds, jank, and leaks.
- It runs in the browser connected to a running app.
77. What is the difference between JIT and AOT compilation?
- JIT compiles at runtime, enabling hot reload during development.
- AOT compiles ahead of time for fast, optimised release builds.
- Debug builds use JIT; release builds use AOT.
- This dual model gives both speed and fast iteration.
78. What are the types of tests in Flutter?
- Unit tests verify logic in isolation.
- Widget tests verify a widget's UI and interaction.
- Integration tests verify whole flows on a device.
- A balanced suite favours many unit/widget tests.
79. What is a widget test?
- It builds a widget in a test environment and interacts with it.
- Use
WidgetTesterto pump and tap. - Find widgets with finders and assert with matchers.
- It runs fast without a real device.
80. How do you mock dependencies in tests?
- Inject dependencies so they can be replaced.
- Use packages like
mockitoormocktail. - Override providers in Riverpod for test doubles.
- This isolates the unit under test.
81. How do you handle different screen sizes?
- Use
MediaQuery,LayoutBuilder, and flexible widgets. - Adopt responsive breakpoints for phone/tablet.
- Use
FractionallySizedBoxand flex for proportions. - Test across device sizes and orientations.
Architecture, Packaging & Release
82. What is the pubspec.yaml file?
- It declares dependencies, assets, fonts, and metadata.
- It controls package versions and constraints.
flutter pub getresolves it.- It is the project's manifest.
83. What is the difference between a package and a plugin?
- A package is pure Dart code shared via pub.dev.
- A plugin also includes native platform code.
- Plugins wrap native SDKs via platform channels.
- Both are added through
pubspec.yaml.
84. How do you structure a large Flutter app?
- Separate UI, business logic, and data layers.
- Use feature-based folders and clear boundaries.
- Adopt a consistent state management approach.
- Apply dependency injection for testability.
85. What is clean architecture in Flutter?
- Layered design separating presentation, domain, and data.
- Dependencies point inward toward the domain.
- It improves testability and swappability.
- It adds structure at the cost of more boilerplate.
86. How do you build a release version of a Flutter app?
- Use
flutter build apk/appbundlefor Android. - Use
flutter build ipafor iOS. - Configure signing and version numbers first.
- Release builds are AOT-compiled and optimised.
87. How do you handle environment configuration (dev/prod)?
- Use flavors (Android) and schemes/configs (iOS).
- Pass values via
--dart-defineat build time. - Keep secrets out of source control.
- Switch API endpoints per environment.
88. What are the pros and cons of Flutter for mobile development?
- Pros: single codebase, fast hot reload, consistent UI, strong performance.
- Cons: larger app size, native integrations need channels.
- Less mature for some platform-specific features than native.
- Great for teams wanting cross-platform speed with one stack.