Flutter interview questions and answers
25 questions · Easy, Medium and Hard
These Flutter questions cover the ground interviewers go over most: widgets and layout, state management, navigation, async code in Dart, and how Flutter draws the screen. Each answer is short and practical, with code where it helps.
For the harder questions, explaining how Flutter works under the hood, such as the three trees, is what stands out.
Easy questions
What is Flutter?
Flutter is Google's open-source toolkit for building apps for mobile, web and desktop from one codebase, written in the Dart language. Instead of using each platform's native widgets, Flutter draws every pixel itself with its own rendering engine, so the app looks and behaves the same across platforms.
Often asked next: How is Flutter different from React Native?
What does "everything is a widget" mean?
In Flutter, the UI is built by nesting widgets: a button, a piece of text, padding, a layout, even the app itself. Widgets are lightweight descriptions of part of the UI, and you build complex screens by composing small widgets. Layout and styling widgets, like Padding, Center and Container, are widgets too.
What is the difference between StatelessWidget and StatefulWidget?
A StatelessWidget has no mutable state; it builds the same UI from the data passed in, such as text or an icon. A StatefulWidget has a separate State object that can change over time, and calls setState() to rebuild when it does, as in a counter, a form or an animated element.
Prefer stateless widgets when you can, because they are simpler and cheaper.
class Counter extends StatefulWidget {
const Counter({super.key});
@override
State<Counter> createState() => _CounterState();
}
class _CounterState extends State<Counter> {
int count = 0;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () => setState(() => count++),
child: Text('Tapped $count times'),
);
}
}What is Dart, and what are its main features?
Dart is the language Flutter uses. It is statically typed with sound null safety, supports async/await and streams, and compiles ahead of time to fast native code for release builds, and just in time during development, which enables hot reload. Its syntax will feel familiar if you know Java, JavaScript or C#.
What is the difference between hot reload and hot restart?
Hot reload injects the changed code into the running app and rebuilds the widgets, keeping the current state, so you see changes in about a second. Hot restart reloads the whole app and resets all state. You need a restart after changes such as new global variables, enums or the main() function.
How do Row, Column, Stack, Expanded and Flexible work?
Row lays children out horizontally and Column vertically. Stack places children on top of each other, positioned with Positioned. Inside a Row or Column, Expanded makes a child fill the remaining space, and Flexible lets it take up to that space but no more. A frequent error is an overflow when text or a list inside a Row or Column has no bounds; wrapping it in Expanded usually fixes it.
What is BuildContext?
BuildContext is a handle to a widget's location in the widget tree. You use it to look up things above the widget, such as the theme with Theme.of(context), the screen size with MediaQuery.of(context), the Navigator, or a provider. Using a context after the widget has been removed, for example after an await, can cause errors, so check mounted first.
What is pubspec.yaml?
pubspec.yaml is the project's configuration file. It lists the app's name and version, the Dart SDK version it needs, its dependencies (packages from pub.dev), and assets such as images and fonts. After changing it, run flutter pub get.
Medium questions
Explain the lifecycle of a StatefulWidget.
The main steps are: createState() creates the State object; initState() runs once when it is inserted, for setup such as starting a controller; didChangeDependencies() runs after initState and whenever an inherited widget it depends on changes; build() runs whenever the UI must be drawn; didUpdateWidget() runs when the parent rebuilds with new configuration; and dispose() runs when the State is removed permanently, to release controllers, streams and timers.
Often asked next: What happens if you forget to dispose a controller?
What does setState do, and what are its limits?
setState tells Flutter that the state of this widget changed, so it schedules a rebuild of that widget and its children. It is fine for state used by one widget. For state shared across many screens, calling it high up rebuilds too much and gets hard to manage, which is why state management solutions exist.
What state management options does Flutter have, and how do you choose?
Common choices are Provider, Riverpod, BLoC (and its simpler form, Cubit) and GetX. Provider and Riverpod are light and good for most apps. BLoC separates UI from business logic with streams of events and states, which suits large apps and teams that want strict structure and easy testing.
Choose by size and team: start with the simplest approach that fits, and stay consistent across the project.
What is the difference between BLoC and Cubit?
A Cubit is a simpler form of BLoC. You call methods on it that emit new states directly. A BLoC receives events, maps each event to new states, and so gives a clear record of what triggered each change. Use a Cubit for simple cases and BLoC when you need the event trail, or event transformations such as debouncing search input.
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}How does navigation work in Flutter?
The basic approach is the Navigator: Navigator.push adds a screen to the stack and Navigator.pop removes it. You can also register named routes and navigate with Navigator.pushNamed, passing data as arguments. For deep links and web URLs, many apps use a router package such as go_router.
Flutter navigation: Navigator, named routes and passing data →
What is the difference between a Future and a Stream?
A Future represents one value that will be available later, such as an HTTP response. A Stream delivers a sequence of values over time, such as location updates or chat messages. In the UI, FutureBuilder rebuilds when a future completes, and StreamBuilder rebuilds on each new event.
FutureBuilder<List<Post>>(
future: fetchPosts(),
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const CircularProgressIndicator();
}
if (snapshot.hasError) return Text('Error: ${snapshot.error}');
return PostList(posts: snapshot.data!);
},
)How do you do heavy work without freezing the UI?
Dart runs your code on one main isolate, so a long calculation, such as parsing a big JSON file or processing an image, blocks the UI and causes dropped frames. Move it to another isolate with Isolate.run() or Flutter's compute(). Isolates do not share memory; they pass messages. Awaiting a Future does not use another thread, so await alone does not solve CPU-heavy work.
What are keys in Flutter, and when do you need them?
Keys help Flutter tell widgets apart when the widget tree changes. You mostly do not need them, but they matter when you reorder, add or remove items in a list of stateful widgets, so the state stays with the right item. ValueKey uses a value such as an ID, and GlobalKey gives access to a widget's state from elsewhere.
Why use const constructors?
A const widget is created once at compile time and reused. Flutter can skip rebuilding it when the parent rebuilds, because it knows it cannot have changed. Using const wherever possible is one of the easiest performance improvements, and the Dart linter will suggest it.
How do you call an API and parse JSON in Flutter?
Use the http or dio package to make the request, decode the body with jsonDecode, and convert it into a model class with a fromJson factory. For larger projects, generate the model code with json_serializable. Always handle loading, error and empty states, and set timeouts.
class Post {
final int id;
final String title;
Post({required this.id, required this.title});
factory Post.fromJson(Map<String, dynamic> json) =>
Post(id: json['id'], title: json['title']);
}
final res = await http.get(Uri.parse(url));
final posts = (jsonDecode(res.body) as List)
.map((e) => Post.fromJson(e)).toList();How do you store data locally in Flutter?
For small key-value data such as settings, use shared_preferences. For structured data, use a database such as SQLite (through sqflite or drift) or Hive. For secrets such as tokens, use flutter_secure_storage, which uses the platform's keychain or keystore, not plain preferences.
Hard questions
What are the three trees in Flutter: widget, element and render object?
The widget tree is the immutable description of the UI that you write; widgets are cheap and get recreated often. The element tree is the live instance of that description: it holds the position and state in the tree and decides whether an existing element can be reused with a new widget. The render object tree does the actual layout and painting.
Because elements are reused when the widget type and key match, Flutter can rebuild widgets constantly without rebuilding everything on screen.
Often asked next: What does Flutter do when a parent rebuilds?
How would you improve the performance of a Flutter app?
Profile first, in profile mode with Flutter DevTools. Then: use const widgets; split big build methods into smaller widgets so less is rebuilt; use ListView.builder for long lists so only visible items are built; avoid expensive work inside build; cache images and resize them; keep state as local as possible; and move heavy computation to an isolate.
What are platform channels?
Platform channels let Dart code call native Android or iOS code, and the other way round, by sending messages. A MethodChannel is the common kind: Dart calls a named method and gets a result from Kotlin, Java, Swift or Objective-C code. Use them when a feature has no Flutter plugin yet; otherwise prefer an existing plugin from pub.dev.
What is an InheritedWidget, and how does Provider relate to it?
An InheritedWidget makes data available to all widgets below it in the tree, and rebuilds the ones that depend on it when the data changes. Widgets read it with context.dependOnInheritedWidgetOfExactType, which is what Theme.of(context) and MediaQuery.of(context) use. The provider package is a convenient wrapper built on this idea, so you do not write the boilerplate yourself.
How do you make a Flutter app responsive across screen sizes?
Use MediaQuery to read the screen size and LayoutBuilder to choose a layout from the space the parent gives you. Use flexible layouts such as Expanded, Wrap and GridView instead of fixed pixel sizes, and design breakpoints, for example one column on phones and two on tablets. Test on small and large devices, and in both orientations.
How do you handle errors and logging in a production Flutter app?
Catch exceptions where you make network or storage calls and show a clear message to the user. Set FlutterError.onError and PlatformDispatcher.instance.onError to catch uncaught errors, and send them to a crash reporting service such as Firebase Crashlytics or Sentry. Avoid printing sensitive data to logs.
Practise in code
Interviews often include a short coding task. These challenges run in your browser.
- MediumArraysChunk an arraySplit an array into smaller arrays of a given size.
- MediumRecursionFlatten a nested arrayTurn an array of any depth into a single flat array.
- MediumHash mapsWord frequencyCount how many times each word appears in a sentence.
- MediumSearchingBinary searchFind a value in a sorted array without checking every item.
Keep learning
Handy free tools
- JSON Formatter & ValidatorFormat, validate and minify JSON in your browser. Shows the exact line and column of any error.
- JSON to TypeScript ConverterTurn any JSON into TypeScript interfaces or types, with optional keys, unions and nested types worked out for you.
- Color Converter & Contrast CheckerConvert colours between HEX, RGB, HSL, HSV, HWB, CMYK and OKLCH, check WCAG contrast and make tints and shades.
- Image ResizerResize pictures to an exact width and height, or by percentage, with ready sizes for social media.
- UUID GeneratorGenerate random (v4) or time-ordered (v7) UUIDs in bulk, and check the version of any UUID.
- API Request Tester (REST Client)Send GET, POST, PUT, PATCH and DELETE requests from your browser, import cURL commands, and copy the code as cURL, fetch, Axios or Python.