Picking a state management approach in Flutter
Flutter doesn’t ship an opinionated state management story, which is freeing until you’re picking one for the third time this year. This is a sample post — replace it with a real writeup — but here’s the shape of the decision.
The short version
- Provider — fine for a small app, or as the layer under something else. Minimal ceremony, but you lose compile-time safety around missing providers.
- Riverpod — Provider’s spiritual successor, compile-safe, no
BuildContextneeded to read state. Reach for this by default on a new app. - Bloc — heavier ceremony (events in, states out), but the discipline pays off on a large app with a big team and complex async flows worth testing in isolation.
A minimal Riverpod provider
final counterProvider = StateProvider<int>((ref) => 0);
class CounterButton extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(counterProvider);
return ElevatedButton(
onPressed: () => ref.read(counterProvider.notifier).state++,
child: Text('Count: $count'),
);
}
} Start with Riverpod unless something specific about the app argues otherwise — it’s the easiest one to be wrong about cheaply.