Add miniriverpod to a Flutter app
Set an SDK constraint that matches the package, then install it. Try ProviderScope and WidgetRef.watch together in a widget.
SDK requirements
Use an SDK constraint that matches the package so your code can run with the SDK you develop against.
Dart SDK
>=3.10.0 <4.0.0
Flutter
>=3.38.0
Check your Dart version
If your app pins Dart below 3.10, update the SDK constraint first. Then run flutter pub get.
Install the package
Install from the command line. Check the changelog before upgrading or changing your version constraint.
CLI
flutter pub add miniriverpod
pubspec.yaml
Add under dependencies
dependencies:
miniriverpod: ^0.0.2
Show a provider value in your app
Wrap your app in ProviderScope, create a Provider, and use a ConsumerWidget to show its value.
import 'package:flutter/widgets.dart';
import 'package:miniriverpod/miniriverpod.dart';
final counterProvider = Provider<int>((ref) => 0);
void main() {
runApp(const ProviderScope(child: CounterApp()));
}
class CounterApp extends ConsumerWidget {
const CounterApp({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final count = ref.watch(counterProvider);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Text('$count')),
);
}
}
Where to go next
How providers work
See how args identify providers, how Scope passes dependencies, and how to do both in Dart.
Learn how providers workRead provider state
Pick when to use watch, read, or listen and learn how to refresh an AsyncProvider.
Learn to read provider state