Riverpod and BLoC are the two state management choices I see most often in serious Flutter codebases in 2026. I have shipped 20+ Flutter apps over 4+ years and led teams at Metasense Technologies and Apptex Software Solutions, and the question "Riverpod or BLoC?" comes up at the start of almost every project. This guide builds the same feature in both, then compares testing, boilerplate, code generation, team scale and performance so you can decide based on your situation rather than on whichever tutorial you read last.
What is the short answer?
Riverpod is the better default for small to mid-sized teams that want to move quickly with less code; BLoC is the better default for larger teams that value strict, event-driven structure and traceability. Both are mature, actively maintained and fully capable of running a large production app.
The real cost in most projects I have inherited was not choosing the "wrong" library. It was a codebase using three patterns at once, with no agreed rules about where logic lives. Whatever you pick, pick one and write the conventions down.
How does Riverpod think about state?
Riverpod treats state as a graph of providers. Each provider declares how to build a value and which other providers it depends on; when a dependency changes, the dependants rebuild automatically.
The key ideas:
- Providers are global declarations, but state is not global. The state lives in a
ProviderContainer(usually theProviderScopeat the root of your app), so tests can create isolated containers. - Dependency injection is built in. A repository is just another provider, and any provider can be overridden in tests or per environment.
- Notifier and AsyncNotifier hold mutable logic.
Notifieris for synchronous state;AsyncNotifieris for state that loads asynchronously and is exposed as anAsyncValuewith loading, data and error cases. - Widgets read with
ref.watchand trigger actions withref.read(provider.notifier).
The mental model is closer to a spreadsheet than to a message bus: change one cell and everything that depends on it recalculates.
How does BLoC think about state?
BLoC treats state as the output of a pipeline: the UI adds events, the bloc handles each event, and it emits new immutable states. Nothing else is allowed to change state.
- Events are explicit classes such as
ProductsFetchedorProductsRefreshed, registered withon<Event>handlers. - States are explicit classes, usually immutable, often with a status enum or a sealed class hierarchy.
- Cubit is the lighter variant. A Cubit exposes methods instead of events and calls
emitdirectly, which removes the event layer when you do not need it. - Widgets use
BlocProvider,BlocBuilder,BlocListenerandcontext.read/context.watchfrom flutter_bloc.
The mental model is a state machine with a log. Every transition has a named cause, which is why teams that need auditability and predictable reviews like it.
What does the same feature look like in Riverpod?
Here is a paginated product list with initial loading, an error state, and "load more" on scroll. I keep the repository identical for both versions so only the state layer differs.
class Product {
const Product({required this.id, required this.name});
final String id;
final String name;
}
abstract class ProductRepository {
Future<List<Product>> fetchPage({required int page, int pageSize = 20});
}
class ProductsPage {
const ProductsPage({
this.items = const [],
this.page = 0,
this.hasMore = true,
this.isLoadingMore = false,
});
final List<Product> items;
final int page;
final bool hasMore;
final bool isLoadingMore;
ProductsPage copyWith({
List<Product>? items,
int? page,
bool? hasMore,
bool? isLoadingMore,
}) =>
ProductsPage(
items: items ?? this.items,
page: page ?? this.page,
hasMore: hasMore ?? this.hasMore,
isLoadingMore: isLoadingMore ?? this.isLoadingMore,
);
}
The Riverpod version, written without code generation so it is clear what is happening:
final productRepositoryProvider = Provider<ProductRepository>((ref) {
return HttpProductRepository(); // your real implementation
});
class ProductsNotifier extends AsyncNotifier<ProductsPage> {
static const _pageSize = 20;
@override
Future<ProductsPage> build() async {
final repo = ref.watch(productRepositoryProvider);
final items = await repo.fetchPage(page: 1, pageSize: _pageSize);
return ProductsPage(items: items, page: 1, hasMore: items.length == _pageSize);
}
Future<void> loadMore() async {
final current = state.asData?.value;
if (current == null || !current.hasMore || current.isLoadingMore) return;
state = AsyncData(current.copyWith(isLoadingMore: true));
try {
final next = await ref
.read(productRepositoryProvider)
.fetchPage(page: current.page + 1, pageSize: _pageSize);
state = AsyncData(current.copyWith(
items: [...current.items, ...next],
page: current.page + 1,
hasMore: next.length == _pageSize,
isLoadingMore: false,
));
} catch (e, st) {
state = AsyncError(e, st);
}
}
Future<void> refresh() async {
ref.invalidateSelf();
await future;
}
}
final productsProvider =
AsyncNotifierProvider<ProductsNotifier, ProductsPage>(ProductsNotifier.new);
And the widget:
class ProductsScreen extends ConsumerWidget {
const ProductsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final products = ref.watch(productsProvider);
return products.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(
child: TextButton(
onPressed: () => ref.invalidate(productsProvider),
child: const Text('Something went wrong. Tap to retry.'),
),
),
data: (page) => ListView.builder(
itemCount: page.items.length + (page.hasMore ? 1 : 0),
itemBuilder: (context, index) {
if (index == page.items.length) {
ref.read(productsProvider.notifier).loadMore();
return const Padding(
padding: EdgeInsets.all(16),
child: Center(child: CircularProgressIndicator()),
);
}
return ListTile(title: Text(page.items[index].name));
},
),
);
}
}
Notice what you did not write: no event classes, no separate state hierarchy for loading and error, and no manual dependency wiring. AsyncValue gives you loading and error for free. The trade-off is that a failed "load more" here replaces the whole list with an error; in production I usually keep the items and store a separate loadMoreError field in ProductsPage instead.
What does the same feature look like in BLoC?
The BLoC version makes every transition explicit: two events, one state class with a status, and handlers registered with on<Event>.
sealed class ProductsEvent {}
final class ProductsFetched extends ProductsEvent {}
final class ProductsRefreshed extends ProductsEvent {}
enum ProductsStatus { initial, loading, success, failure }
class ProductsState {
const ProductsState({
this.status = ProductsStatus.initial,
this.items = const [],
this.page = 0,
this.hasMore = true,
});
final ProductsStatus status;
final List<Product> items;
final int page;
final bool hasMore;
ProductsState copyWith({
ProductsStatus? status,
List<Product>? items,
int? page,
bool? hasMore,
}) =>
ProductsState(
status: status ?? this.status,
items: items ?? this.items,
page: page ?? this.page,
hasMore: hasMore ?? this.hasMore,
);
}
class ProductsBloc extends Bloc<ProductsEvent, ProductsState> {
ProductsBloc(this._repo) : super(const ProductsState()) {
// droppable() from bloc_concurrency ignores scroll events while a fetch is running
on<ProductsFetched>(_onFetched, transformer: droppable());
on<ProductsRefreshed>(_onRefreshed);
}
final ProductRepository _repo;
static const _pageSize = 20;
Future<void> _onFetched(ProductsFetched event, Emitter<ProductsState> emit) async {
if (!state.hasMore) return;
if (state.items.isEmpty) emit(state.copyWith(status: ProductsStatus.loading));
try {
final next = await _repo.fetchPage(page: state.page + 1, pageSize: _pageSize);
emit(state.copyWith(
status: ProductsStatus.success,
items: [...state.items, ...next],
page: state.page + 1,
hasMore: next.length == _pageSize,
));
} catch (_) {
emit(state.copyWith(status: ProductsStatus.failure));
}
}
Future<void> _onRefreshed(ProductsRefreshed event, Emitter<ProductsState> emit) async {
emit(const ProductsState());
add(ProductsFetched());
}
}
The widget side:
BlocProvider(
create: (context) => ProductsBloc(context.read<ProductRepository>())..add(ProductsFetched()),
child: BlocBuilder<ProductsBloc, ProductsState>(
builder: (context, state) {
if (state.status == ProductsStatus.loading) {
return const Center(child: CircularProgressIndicator());
}
if (state.status == ProductsStatus.failure) {
if (state.items.isEmpty) {
return Center(
child: TextButton(
onPressed: () => context.read<ProductsBloc>().add(ProductsRefreshed()),
child: const Text('Something went wrong. Tap to retry.'),
),
);
}
}
return ListView.builder(
itemCount: state.items.length + (state.hasMore ? 1 : 0),
itemBuilder: (context, index) {
if (index == state.items.length) {
context.read<ProductsBloc>().add(ProductsFetched());
return const Center(child: CircularProgressIndicator());
}
return ListTile(title: Text(state.items[index].name));
},
);
},
),
)
It is more code, but look at what it buys you: a failed "load more" keeps the existing list by default, concurrency is a one-line transformer decision, and every state change can be traced back to a named event. You also need a RepositoryProvider (or another DI approach such as get_it) higher in the tree, because flutter_bloc does not inject dependencies on its own the way Riverpod does.
If the event layer feels heavy for a screen like this, a Cubit with fetchNextPage() and refresh() methods is a perfectly valid middle ground. You lose event transformers but keep the BLoC structure and tooling.
How do you test each one?
Both are easy to unit test without pumping widgets. Riverpod tests run through a ProviderContainer with overrides; BLoC tests use the bloc_test package to assert the exact sequence of emitted states.
Riverpod:
test('loads the first page', () async {
final container = ProviderContainer(
overrides: [productRepositoryProvider.overrideWithValue(FakeProductRepository())],
);
addTearDown(container.dispose);
final page = await container.read(productsProvider.future);
expect(page.items, hasLength(20));
expect(page.page, 1);
});
BLoC:
blocTest<ProductsBloc, ProductsState>(
'emits loading then success on first fetch',
build: () => ProductsBloc(FakeProductRepository()),
act: (bloc) => bloc.add(ProductsFetched()),
expect: () => [
isA<ProductsState>().having((s) => s.status, 'status', ProductsStatus.loading),
isA<ProductsState>().having((s) => s.items.length, 'items', 20),
],
);
In my experience, blocTest makes regression tests very readable because the expected list of states doubles as documentation. Riverpod's strength is overrides: swapping any dependency, at any depth, without touching constructors. I lean on that heavily for repositories and API clients.
Which one has less boilerplate, and does code generation help?
Riverpod has less boilerplate per feature, and riverpod_generator reduces it further. BLoC has more classes by design, and freezed is the usual way to cut down the repetitive state and event code.
With riverpod_generator, the notifier above shrinks to an annotated class and the provider is generated for you:
@riverpod
class Products extends _$Products {
@override
Future<ProductsPage> build() async {
final items = await ref.watch(productRepositoryProvider).fetchPage(page: 1);
return ProductsPage(items: items, page: 1, hasMore: items.length == 20);
}
// loadMore() and refresh() stay the same
}
// generates: productsProvider
On the BLoC side, freezed generates copyWith, equality and sealed unions for states and events, which removes most of the hand-written code in the example above. The cost in both cases is a build_runner step in your workflow and CI. On larger projects I keep generated files out of code review diffs and run the generator in CI to catch stale output.
Codegen is optional in both. If your team dislikes build_runner, plain Riverpod notifiers and hand-written BLoC states both work fine. My data class conventions are covered in more depth in my guide to Flutter models.
Which scales better for larger teams?
BLoC tends to scale more predictably across large teams because it forces one shape on every feature; Riverpod scales well too, but only if you agree on conventions up front.
When I led Flutter teams, the problems that hurt were rarely technical limits. They were inconsistency: one developer putting API calls in widgets, another inside providers, a third in a service locator. BLoC's structure makes that harder to do by accident, and reviewers can check a new feature against a familiar template: events, states, bloc, tests.
Riverpod gives you more freedom, which is great for speed and dangerous without rules. The conventions I set on Riverpod projects:
- Repositories and clients are plain
Providers; screen state lives inNotifierorAsyncNotifier. - Widgets only
watchstate and call notifier methods; no business logic inbuild. - One feature folder per screen with its providers, state class and tests together.
- No
ref.readinsidebuildto get values that should be watched.
This lines up closely with the MVVM layering I describe in why MVVM matters in Flutter: the notifier or bloc is your view model, and the repository is your model layer.
Is there a performance difference?
For typical apps, no meaningful one. Both rebuild only the widgets that listen to the state that changed, and the bottleneck is almost always widget structure, not the state library.
Where the details matter:
- Riverpod: use
ref.watch(provider.select((s) => s.field))so a widget rebuilds only when the field it uses changes. UseautoDispose(the default with codegen) so screen state is released when you leave the screen. - BLoC: use
buildWhenonBlocBuilderorBlocSelectorto limit rebuilds, and make sure states implement equality (freezed or equatable) so identical states are not re-emitted as changes. - Both: keep large lists in
ListView.builder, keep heavy JSON parsing off the UI thread, and profile in profile mode on a real device.
If you are chasing jank, start with my Flutter performance checklist before blaming the state layer.
Where do Provider and GetX fit?
Provider is the predecessor to Riverpod and is still fine for small apps, but for new projects I reach for Riverpod instead. GetX is fast to start with but bundles routing, DI and state together, which makes larger codebases harder to test and reason about.
Provider depends on the widget tree and BuildContext, so you can hit ProviderNotFoundException at runtime when something is read from the wrong place. Riverpod was created by the same author partly to remove that class of error. If you have an existing Provider app, migrating screen by screen to Riverpod is usually straightforward.
GetX works, and I have maintained GetX apps. If you are on it, my GetX best practices guide covers how to keep it under control. For a new app that you expect to grow, I would not start there.
How do Riverpod and BLoC compare side by side?
| Aspect | Riverpod | BLoC / Cubit |
|---|---|---|
| Mental model | Reactive provider graph | Events in, states out |
| Boilerplate | Low, lower with riverpod_generator | Higher, reduced with freezed or Cubit |
| Dependency injection | Built in, overridable | Via RepositoryProvider or get_it |
| Async loading / error | AsyncValue built in | Modelled in your own state class |
| Concurrency control | Manual guards in notifier methods | Event transformers (droppable, restartable, sequential) |
| Traceability | Good with ProviderObserver | Excellent: every change has a named event; BlocObserver |
| Testing | ProviderContainer + overrides | bloc_test with expected state sequences |
| Depends on BuildContext | No (uses ref) | Yes for lookup (context.read) |
| Learning curve | Moderate: many provider types and ref rules | Moderate: more classes but one consistent pattern |
| Best fit | Solo devs, startups, small to mid teams | Larger teams, regulated or audit-heavy domains |
Should you choose Riverpod or BLoC?
Use this checklist. If most of your answers land in one column, that is your choice.
Choose Riverpod if:
- You are a solo developer or a small team that needs to ship an MVP quickly.
- You want dependency injection and test overrides without an extra package.
- Most of your state is "fetch data, show loading, show error, show data".
- You want state that does not depend on
BuildContext. - You are comfortable setting and enforcing your own conventions.
Choose BLoC if:
- Several developers or teams will work on the codebase and you want one enforced shape.
- You need a clear log of what caused each state change, for debugging or auditing.
- You have complex flows where event ordering and concurrency matter (search-as-you-type, multi-step forms, real-time updates).
- Your team already knows BLoC; retraining has a real cost.
- You prefer explicit code over less code.
On my own projects, I pick based on the team and the product, not on preference. For a 30-day MVP where I lock architecture in the first three days and ship weekly builds, Riverpod's lower ceremony usually wins. For a product that a client's in-house team will own long term, I ask what they know first.
Frequently Asked Questions
Is Riverpod replacing BLoC in 2026?
No. Both are actively maintained and widely used in production. Riverpod has grown fast among new projects and small teams, while BLoC remains common in larger organisations and long-lived codebases. Treat them as two good options with different trade-offs rather than one replacing the other.
Can I use Riverpod and BLoC in the same app?
Technically yes; for example, Riverpod can provide repositories while some screens use Cubits. In practice I avoid it, because new developers then have to learn two patterns and guess which one to use. If you are migrating, mix them only temporarily and set a clear direction.
Should I use Cubit or Bloc?
Start with Cubit for simple screens where methods map directly to state changes. Move to Bloc when you need event transformers such as debouncing or dropping duplicate requests, or when a traceable event log is valuable. Both share the same widgets, testing tools and observers, so switching later is cheap.
Do I need code generation for Riverpod?
No. riverpod_generator is optional. It reduces boilerplate and picks sensible defaults like auto-dispose, but plain Notifier and AsyncNotifier classes with manually declared providers work fully. If your team already uses build_runner for freezed or json_serializable, adding riverpod_generator costs very little extra.
Which is easier for beginners?
Cubit is often the easiest to understand first because it is just a class with methods that emit states. Riverpod has more concepts up front, such as provider types, ref.watch versus ref.read and auto-dispose, but less code per feature once those concepts click.
Is GetX a good alternative to both?
GetX is quick to start with, but it combines routing, dependency injection and state in one package with global access, which makes larger apps harder to test and reason about. For new apps that will grow, I recommend Riverpod or BLoC over GetX.
If you are starting a Flutter app and want the architecture decided properly from day one, or you have an existing codebase with tangled state management, I can help through my Flutter development service. You can also get in touch to talk through your project.