Flutter Lesson 82 of 83 9 min read
Flutter Interview Questions and Answers
Fifty common Flutter interview questions with clear answers: widgets, state, layout, navigation, async, performance, testing and release.
On this page
These are the questions asked most often in Flutter interviews. Answers are brief on purpose, and each links to the lesson with the detail. Try answering aloud before you read.
For questions about the language itself, see the Dart interview questions.
Fundamentals #
1. What is Flutter?
An open-source UI toolkit from Google for building apps for Android, iOS, web and desktop from one Dart codebase. It draws its own interface with its own rendering engine. See what is Flutter.
2. How is Flutter different from React Native?
Flutter compiles Dart to native code and renders every pixel itself, so the UI is identical across platforms. React Native runs JavaScript and maps components to the platform’s native views.
3. What is a widget?
An immutable description of part of the user interface. Everything visible, and much that is not, such as padding and alignment, is a widget. See widgets.
4. What is the difference between StatelessWidget and StatefulWidget?
A stateless widget depends only on its constructor arguments. A stateful widget has a State object that holds data which can change, and calls setState to rebuild.
5. What are the widget, element and render trees?
The widget tree is the configuration you write. The element tree holds the long-lived instances that link widgets to their state and position. The render tree does layout and painting. Widgets are cheap and rebuilt often; elements and render objects are reused.
6. What is BuildContext?
A handle to a widget’s location in the tree. It is used to find ancestors such as Theme, MediaQuery and Navigator.
7. What does setState do?
It runs the given function, marks the state as dirty, and schedules a rebuild of that widget’s subtree.
8. Describe the lifecycle of a StatefulWidget.createState, initState, didChangeDependencies, build, then didUpdateWidget and build as needed, and finally deactivate and dispose. See widget lifecycle.
9. What is the difference between hot reload and hot restart?
Hot reload injects changed code and rebuilds, keeping state. Hot restart restarts the Dart code from main and loses state. See hot reload.
10. Why use const constructors?
A const widget is created once at compile time and Flutter can skip rebuilding it, which improves performance.
11. What are keys, and when do you need them?
Keys identify widgets across rebuilds. They are needed when stateful widgets of the same type are reordered, added or removed in a list. See keys.
12. What is the difference between main() and runApp()?main is the entry point of the Dart program. runApp takes the root widget and attaches it to the screen.
Layout #
13. How does layout work in Flutter?
Constraints go down, sizes go up, and the parent sets the position. See how layout works.
14. What is the difference between Expanded and Flexible?
Both take a share of free space in a row or column. Expanded forces the child to fill it. Flexible lets the child be smaller. See Expanded and Flexible.
15. What causes “RenderFlex overflowed”, and how do you fix it?
The children of a row or column need more space than is available. Wrap the flexible child in Expanded or Flexible, or make the content scroll.
16. What is the difference between Container and SizedBox?SizedBox only sets a size. Container combines size, padding, margin, alignment and decoration. Prefer the simpler widget when it is enough.
17. What is the difference between ListView and ListView.builder?ListView with a children list builds every child at once. ListView.builder builds only the visible items, which suits long lists.
18. What are slivers?
Scrollable pieces used inside a CustomScrollView. They allow lists, grids and collapsing app bars to scroll together efficiently. See scrolling and slivers.
19. What is the difference between MediaQuery and LayoutBuilder?MediaQuery describes the whole screen and device settings. LayoutBuilder gives the constraints of the widget’s parent, which is better for reusable components.
20. What does SafeArea do?
It pads its child to avoid notches, the status bar and system gesture areas.
State management #
21. What is the difference between ephemeral state and app state?
Ephemeral state belongs to one widget, such as a selected tab. App state is shared across the app, such as the signed-in user. See state basics.
22. What does “lifting state up” mean?
Moving state to the nearest common ancestor of the widgets that need it, passing data down and callbacks up.
23. What is InheritedWidget?
A widget that makes data available to its descendants through context, and rebuilds those that depend on it when the data changes. Theme and Provider are built on it.
24. Explain Provider.
A package that wraps InheritedWidget. A model, usually a ChangeNotifier, is placed above part of the tree. Widgets use context.watch to rebuild on changes and context.read to call methods. See Provider.
25. What is the difference between context.watch and context.read?watch subscribes the widget to changes and is used in build. read gets the object once without subscribing and is used in callbacks.
26. How does Riverpod differ from Provider?
Providers are global declarations, not widgets, so they do not depend on BuildContext, cannot fail with “provider not found”, combine easily, and handle async state with AsyncValue. See Riverpod.
27. What is the Bloc pattern?
The UI sends events to a bloc, which emits states in response. The UI rebuilds from states. Cubit is the simpler form, with methods instead of events. See Bloc.
28. What is the difference between ChangeNotifier and ValueNotifier?ValueNotifier holds a single value and notifies when it is replaced. ChangeNotifier is a base class for models with several fields, where you call notifyListeners yourself.
Navigation #
29. How does navigation work in Flutter?
The Navigator manages a stack of routes. push adds a screen and pop removes the top one. See navigator basics.
30. How do you pass data to a screen, and get a result back?
Pass data through the new page’s constructor. Return a result by passing it to Navigator.pop, and await the push. See passing data.
31. What is the difference between push and pushReplacement?push adds a route on top. pushReplacement replaces the current route, so back does not return to it.
32. Why use go_router?
For URL-based routing: deep links, web address bar support, redirects and nested navigation, all declared in one place. See go_router.
33. How do you intercept the back button?
With PopScope, setting canPop and handling onPopInvokedWithResult.
Async and data #
34. What is the difference between FutureBuilder and StreamBuilder?FutureBuilder rebuilds once when a single future completes. StreamBuilder rebuilds on every event of a stream.
35. Why should you not create a future inside build?build runs many times, so the request would restart on every rebuild. Create it once in initState or a state holder.
36. Why check mounted after an await?
The widget may have been removed while waiting. Calling setState or using context then is an error.
37. How do you run heavy work without freezing the UI?
In a separate isolate, with compute or Isolate.run. async alone does not help, because it still runs on the UI thread.
38. What options are there for local storage?shared_preferences for small key-value data, files for documents, SQLite (sqflite, drift) for structured data, and flutter_secure_storage for secrets. See storing data.
39. How do you convert JSON into objects?
With model classes that have fromJson and toJson, written by hand or generated with json_serializable or freezed.
Animations #
40. What is the difference between implicit and explicit animations?
Implicit animations, such as AnimatedContainer, animate automatically when a property changes. Explicit animations use an AnimationController that you start, stop and repeat yourself.
41. What is a Tween?
An object that maps the controller’s 0 to 1 range onto a range of values, such as sizes, colours or offsets.
42. What is a Hero animation?
A shared element transition: a widget with the same tag on two screens animates from one to the other during navigation.
43. What does vsync do?
It ties the animation to the screen’s refresh, and stops it ticking when the widget is not visible, saving battery.
Performance, testing and release #
44. How do you improve Flutter performance?
Use const, keep rebuilds small, build lists lazily, size images properly, avoid costly effects such as large Opacity, move heavy work to isolates, and measure in profile mode. See performance.
45. What are the build modes?
Debug (hot reload, assertions, slow), profile (performance measurement) and release (optimised, for users).
46. What kinds of test does Flutter support?
Unit tests for logic, widget tests for UI components, and integration tests for the whole app on a device. See testing.
47. What is the difference between a package and a plugin?
A package is Dart code only. A plugin also contains native code for accessing platform features.
48. How does Flutter call native code?
Through platform channels: a MethodChannel sends a message to Kotlin or Swift code and receives a result. See platform channels.
49. What is the difference between an APK and an app bundle?
An APK is an installable file. An app bundle (.aab) is uploaded to Google Play, which generates optimised APKs for each device.
50. How would you structure a large Flutter app?
Feature-first folders, a UI layer (views and view models) separate from a data layer (repositories and services), dependencies injected, and tests for each layer. See architecture.
Questions about your own work #
Technical answers are half the interview. Be ready to talk about:
- An app you built, and one decision you would make differently now.
- The hardest bug you fixed, and how you found it.
- Which state management approach you prefer, and why, including its drawbacks.
- How you would break a design into widgets, working aloud from a screenshot.
- How you keep up with changes in Flutter.
How to prepare #
- For each question, write a ten-line example that demonstrates the answer.
- Practise explaining aloud. Clear explanation is a skill of its own.
- Build something small in a timed hour, the way a take-home task works.
- When you do not know, say so, and reason towards an answer.
Try it yourself #
Answer ten questions a day for five days with the answers covered. Mark the ones you miss, reread the linked lessons, and try those again a week later.