Intermediate Flutter Interview Questions
14 questions
Explain the widget lifecycle in Flutter.
A StatefulWidget's State goes through createState → initState → didChangeDependencies → build (repeated) → didUpdateWidget (on parent rebuild) → deactivate → dispose.
Describe Flutter's architecture — how does a widget end up as pixels on screen?
Flutter has three parallel trees — Widget, Element, and RenderObject — where widgets are immutable configuration, elements are the mutable instances that manage the tree, and render objects handle layout, painting, and hit-testing.
What is the difference between Future and Stream in Dart?
A Future represents a single asynchronous value that completes once; a Stream represents a sequence of asynchronous values delivered over time, and can emit zero, one, or many events.
What are extension methods in Dart?
Extension methods let you add new functionality to an existing type — including types you don't own, like String or int — without modifying its source or subclassing it.
What are mixins in Dart and when would you use one?
A mixin lets a class reuse a chunk of behavior from multiple sources without using multiple inheritance — you declare it with `mixin` and apply it with `with`.
How does Riverpod differ from Provider?
Riverpod is a redesign by the same author as Provider that removes the dependency on BuildContext and the widget tree, catching errors at compile time instead of runtime, and making providers globally accessible and easily testable.
What is the BLoC pattern in Flutter?
BLoC (Business Logic Component) separates UI from business logic by having the UI dispatch Events into a Bloc, which processes them and emits new States that the UI rebuilds from — all communication happens through a strict, unidirectional stream of Events and States.
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`.
What's the difference between Firestore and the Realtime Database?
Firestore is a newer, document/collection-based database with richer querying, automatic multi-region scaling, and better offline support; the Realtime Database is a simpler single JSON tree, cheaper for very high-frequency small writes but with weaker querying.
How do push notifications work with Firebase Cloud Messaging in Flutter?
The app registers with FCM to get a unique device token, your backend (or Firebase console) sends a message to that token via the FCM API, and the `firebase_messaging` package delivers it to the app in foreground, background, or terminated states via different handlers.
What is Clean Architecture and how does it apply to Flutter?
Clean Architecture separates an app into independent layers — typically presentation, domain, and data — where inner layers (business logic) never depend on outer layers (UI, frameworks, databases), so business rules can be tested and reused independently of Flutter itself.
What is the Repository pattern?
The Repository pattern puts a single abstraction in front of however data is actually fetched or stored — network, local cache, database — so the rest of the app talks to one consistent interface and doesn't care where the data comes from.
What are the main ways to build animations in Flutter?
Implicit animations (the `Animated*` widgets, like `AnimatedContainer`) animate a property change automatically with minimal code; explicit animations give full control via an `AnimationController` and `Tween`, for anything beyond a simple property tween.