A Riverpod provider for Flutter State Restoration


Riverpod doesn't provide a simple way to restore state when an app gets killed by the OS. This package provides a way to do that.


How to register global providers for restoration:

final counterProvider = RestorableProvider(
  // our default value
  (ref) => RestorableInt(0),
  // each provider needs a unique restorationId
  restorationId: 'counterProvider',

  // Required to restore state
  restorationScopeId: 'root',
  // Required to register global providers for restoration
  builder: (context, child) => RestorableProviderRegister(
    restorationId: 'app',
    providers: [
      // list your global restorable providers here
    child: child ?? const SizedBox.shrink(),

How to register overridden providers for restoration:

  restorationId: 'counter_page_scope',
  overrides: [
    // if you only use the overriden restorable provider, you only need to add it here.
    counterProvider.overrideWith((ref) => RestorableInt(0)),
  child: const CounterPage(),

Additional information

For information on how to restore navigation, see the example or https://api.flutter.dev/flutter/widgets/Navigator-class.html#state-restoration