Skip to content

A set of ref extensions to enhance riverpod packages. Used at theodo apps β€οΈπŸ’™πŸ’›

License

Notifications You must be signed in to change notification settings

bamlab/riverpod_community_extensions

Repository files navigation

Riverpod Community Extensions

logo

Useful extensions on ref types for Riverpod.

Ref types are the way to interact with providers in Riverpod. They are built to be composable and flexible. This package provides some useful extensions on ref types to make them even more powerful and easily add common functionalities on your providers, such as auto-refreshing for example.

Features πŸš€

This package adds the following methods to ref types:

  • cacheFor on AutoDisposeRef - Prevents the provider from being disposed for the specified duration.

  • cacheDataFor on AutoDisposeFutureProviderRef - Keeps the data of the future provider for the specified duration.

  • debounce on AutoDisposeFutureProviderRef - Wait for a specified duration before calling the provider's computation, and cancel the previous call if a new one is made.

  • autoRefresh on AutoDisposeRef - Refreshes the value at a specified interval. Useful for scenarios where periodic updates of a provider's value are required.

  • refreshWhenReturningToForeground on AutoDisposeRef - Refreshes the provider's value each time the app returns to the foreground, ensuring the data is always up to date after returning to the app.

  • refreshWhenNetworkAvailable on AutoDisposeFutureProviderRef - Automatically refresh the provider when the network is available if it has error state. Uses the package connectivity_plus.

Installation πŸ’»

❗ In order to start using Riverpod Community Extensions you must have the Dart SDK installed on your machine.

Install via dart pub add:

dart pub add riverpod_community_extensions

Usage 🎨

Simply import the package and use the provided extensions on your ref types.

Example without codegen:

import 'package:riverpod_community_extensions/riverpod_community_extensions.dart';
import 'package:riverpod/riverpod.dart';

final dataProvider = FutureProvider.autoDispose((ref) async {
  ref.cacheDataFor(const Duration(minutes: 5));
  return fetchData();
});

Example with codegen:

import 'package:riverpod_community_extensions/riverpod_community_extensions.dart';
import 'package:riverpod/riverpod.dart';

part 'data_provider.g.dart';

@riverpod
Future<int> data((ref) async {
  ref.cacheDataFor(const Duration(minutes: 5));
  return fetchData();
});

πŸ‘‰ About Theodo apps

We are a 130 people company developing and designing universal applications with React Native and Flutter using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by email or through or contact form!

We will always answer you with pleasure 😁


Contributing 🀝

If you want to contribute to this project, please read the CONTRIBUTE.md file.

About

A set of ref extensions to enhance riverpod packages. Used at theodo apps β€οΈπŸ’™πŸ’›

Resources

License

Stars

Watchers

Forks

Packages

No packages published