flutter_riverpod_restorable 2.0.0 copy "flutter_riverpod_restorable: ^2.0.0" to clipboard
flutter_riverpod_restorable: ^2.0.0 copied to clipboard

A Riverpod provider for Flutter State Restoration

A Riverpod provider for Flutter State Restoration

Features #

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.

Usage #

How to register global providers for restoration:

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

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

How to register overridden providers for restoration:

RestorableProviderScope(
  restorationId: 'counter_page_scope',
  restorableOverrides: [
    // use overrideWithRestorable instead of overrideWithValue
    counterProvider.overrideWithRestorable(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

10
likes
120
pub points
56%
popularity

Publisher

unverified uploader

A Riverpod provider for Flutter State Restoration

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, flutter_riverpod, riverpod

More

Packages that depend on flutter_riverpod_restorable