State Management Flutter Interview Questions
9 questions
What is the Provider package and how does it work?
Provider is a wrapper around Flutter's InheritedWidget that makes it easy to expose and listen to a piece of state from anywhere below it in the widget tree, and to rebuild only the widgets that actually depend on it.
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.
What is GetX and what does it offer for state management?
GetX is an all-in-one Flutter package combining reactive state management, dependency injection, and route navigation, designed to minimize boilerplate with a small, simple API.
What does Riverpod's code generation (@riverpod annotation) add over manually-declared providers?
The @riverpod annotation (via riverpod_generator) generates the provider boilerplate for you from a plain function or class, reducing verbosity and catching more mistakes at compile time, at the cost of needing a code-generation build step.
What's the difference between Bloc and Cubit?
Cubit is a simplified version of Bloc — you call methods directly to emit new states, instead of dispatching Events that get mapped to states — trading some of Bloc's structure and traceability for less boilerplate.
How does GetX's Obx widget know when to rebuild?
Obx subscribes to any .obs observable read inside its builder function during the build — it tracks reads via a global tracking mechanism, rather than requiring you to explicitly declare which values it depends on.
What is ProxyProvider used for in the Provider package?
ProxyProvider lets you create a provider whose value depends on one or more other providers above it — for example, building a repository that needs an already-provided API client.
How do you decide which state management solution to use in a new Flutter project?
For most new apps, Riverpod is a safe default — for very small apps, setState alone is often enough; choose BLoC specifically when your team values strict, explicit event-driven architecture; avoid picking based on trend alone.