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')),
    );
  }
}
Use Provider((ref) => ...) for a value you can return right away.
Use AsyncProvider<T>((ref) async => ...) for a Future. To connect a Stream, call ref.emit(stream).
Run a mutation with ref.invoke(provider.method()).

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 work

Read provider state

Pick when to use watch, read, or listen and learn how to refresh an AsyncProvider.

Learn to read provider state

API Reference

Look up invalidate, refreshValue, keepAlive, and invoke.

Look up an API