Back to All Articles
Flutter
Architecture

State Management in Flutter: Riverpod vs BLoC vs Provider

An honest, practical comparison of the three dominant state management approaches in Flutter — with guidance on when to use each.

A

Abhinav Birajdar

Creator

November 28, 202410 min read
State Management in Flutter: Riverpod vs BLoC vs Provider

The State Management Problem

Every Flutter app beyond "Hello World" needs a way to manage state: user data, API responses, UI state, and the relationships between them. Flutter doesn't prescribe an approach, which is both its strength and its source of endless community debate.

This guide cuts through the noise with an honest assessment of the three dominant options in 2025.


Option 1: Provider

Provider is Flutter's officially recommended solution for simple to medium-complexity state.

Best for: Small to medium apps, teams new to Flutter, quick prototypes

Core concept: ChangeNotifier + Consumer widgets

dart
1// Define state
2class CartNotifier extends ChangeNotifier {
3  final List<Product> _items = [];
4  List<Product> get items => List.unmodifiable(_items);
5  int get count => _items.length;
6
7  void add(Product product) {
8    _items.add(product);
9    notifyListeners();
10  }
11
12  void remove(Product product) {
13    _items.remove(product);
14    notifyListeners();
15  }
16}
17
18// Provide state
19ChangeNotifierProvider(
20  create: (_) => CartNotifier(),
21  child: const MyApp(),
22)
23
24// Consume state
25Consumer<CartNotifier>(
26  builder: (context, cart, _) => Text('Items: ${cart.count}'),
27)
28
29// Or with context.watch (simpler)
30final count = context.watch<CartNotifier>().count;

Pros: Simple, official, well-documented Cons: Boilerplate grows quickly, difficult to unit test, easy to accidentally rebuild too much of the tree


Option 2: Riverpod

Riverpod is a complete rewrite of Provider — fixing its limitations while keeping its simplicity. In 2025, it's the recommended choice for most new Flutter projects.

Best for: Most new projects, teams that value testability and type safety

Core concept: Providers declared globally, consumed with hooks or ref

dart
1// providers/cart_provider.dart
2final cartProvider = StateNotifierProvider<CartNotifier, CartState>((ref) {
3  return CartNotifier();
4});
5
6class CartState {
7  final List<Product> items;
8  const CartState({this.items = const []});
9
10  CartState copyWith({List<Product>? items}) =>
11      CartState(items: items ?? this.items);
12
13  int get count => items.length;
14  double get total => items.fold(0, (sum, item) => sum + item.price);
15}
16
17class CartNotifier extends StateNotifier<CartState> {
18  CartNotifier() : super(const CartState());
19
20  void add(Product product) {
21    state = state.copyWith(items: [...state.items, product]);
22  }
23
24  void remove(Product product) {
25    state = state.copyWith(
26      items: state.items.where((i) => i.id != product.id).toList(),
27    );
28  }
29}
dart
1// In a widget (using ConsumerWidget)
2class CartButton extends ConsumerWidget {
3  
4  Widget build(BuildContext context, WidgetRef ref) {
5    final count = ref.watch(cartProvider.select((s) => s.count));
6    // .select() means only rebuilds when count changes, not entire CartState
7
8    return Badge(
9      label: count.toString(),
10      child: IconButton(
11        icon: const Icon(Icons.shopping_cart),
12        onPressed: () => context.push('/cart'),
13      ),
14    );
15  }
16}

Pros: Type-safe, compile-time errors for missing providers, excellent testing support, auto-dispose, family providers for parameterized state Cons: Steeper initial learning curve, requires code generation for full power (riverpod_generator)


Option 3: BLoC (Business Logic Component)

BLoC is a pattern built on Dart Streams. It enforces strict separation between UI and business logic — making it ideal for large teams and complex domains.

Best for: Enterprise applications, large teams, complex state with many events and states

Core concept: Events go in → States come out

dart
1// Events
2sealed class CartEvent {}
3class CartItemAdded extends CartEvent {
4  final Product product;
5  const CartItemAdded(this.product);
6}
7class CartItemRemoved extends CartEvent {
8  final String productId;
9  const CartItemRemoved(this.productId);
10}
11class CartCleared extends CartEvent {}
12
13// States
14sealed class CartState {}
15class CartInitial extends CartState {}
16class CartLoading extends CartState {}
17class CartLoaded extends CartState {
18  final List<Product> items;
19  const CartLoaded(this.items);
20  double get total => items.fold(0, (sum, p) => sum + p.price);
21}
22class CartError extends CartState {
23  final String message;
24  const CartError(this.message);
25}
26
27// BLoC
28class CartBloc extends Bloc<CartEvent, CartState> {
29  CartBloc() : super(CartInitial()) {
30    on<CartItemAdded>(_onItemAdded);
31    on<CartItemRemoved>(_onItemRemoved);
32    on<CartCleared>(_onCleared);
33  }
34
35  Future<void> _onItemAdded(CartItemAdded event, Emitter<CartState> emit) async {
36    if (state is CartLoaded) {
37      final currentItems = (state as CartLoaded).items;
38      emit(CartLoaded([...currentItems, event.product]));
39    }
40  }
41}
dart
1// In a widget
2BlocBuilder<CartBloc, CartState>(
3  builder: (context, state) => switch (state) {
4    CartInitial() => const SizedBox.shrink(),
5    CartLoading() => const LoadingIndicator(),
6    CartLoaded(:final items) => CartItemList(items: items),
7    CartError(:final message) => ErrorView(message: message),
8  },
9)

Pros: Explicit state machine, highly testable, great for async flows, scales to large teams, excellent tooling (flutter_bloc DevTools) Cons: Significant boilerplate, overkill for small apps, steeper learning curve


Decision Guide

ScenarioRecommended
New to FlutterProvider
New greenfield projectRiverpod
Large team / enterpriseBLoC
Simple local UI stateuseState (flutter_hooks) or ValueNotifier
Prototype / hackathonProvider or Riverpod
Complex async flowsBLoC or Riverpod with AsyncNotifier
You value type safetyRiverpod
You value explicitnessBLoC

The Honest Take

In 2025, Riverpod is the best default for new projects. It improves on Provider in almost every way, scales to complexity better than Provider, and is less verbose than BLoC for typical use cases.

Use BLoC if you're on a large team, need strict separation of concerns, or are working in an organization that has already standardized on it.

Use Provider if you're learning Flutter or maintaining an existing Provider-based codebase — it's still a great choice for its intended scope.


Mixing Is Fine

Real apps often use multiple approaches:

  • Riverpod for global app state (user session, theme, settings)
  • ValueNotifier / useState for local, ephemeral UI state
  • BLoC for specific complex features if the team already knows it well

Don't let perfect be the enemy of shipped.