State Management in Flutter Using Riverpod | Sailesh Verma

State Management in Flutter Using Riverpod

Riverpod is a provider-based library that aids in predicting and effectively managing the state of your Flutter application.

It is compile-safe since all providers are declared globally and can be accessed anywhere. This means that you can create providers to hold your application state and business logic outside the widget tree.

makes it easier to only rebuild your providers and widgets when needed.


There are three variants of Riverpod packages available:

flutter_riverpod: A basic way of using Riverpod with flutter.

hooks_riverpod: A way to use both flutter_hooks and Riverpod together.

riverpod: A version of Riverpod with all the classes related to Flutter stripped out.

The idea of providers, which are objects that store and supply values to other components of your application, is introduced by Riverpod. Providers can stand in for any item that needs to be accessed by numerous widgets, including application-level state, services, dependencies, and other objects.

Riverpod's capacity to manage the state in a more declarative and immutable manner is one of its distinguishing characteristics.

These are some of the main ideas of Riverpod:

1. Provider: A provider is an object that can be accessed by other components of your application and holds a value. Various methods, including "Provider," "ScopedProvider," "FutureProvider," "StreamProvider," etc., can be used to construct providers.

2. Consumer: A widget that rebuilds itself when a value changes and keeps track of provider changes. Consumers can leverage a provider's value to design their own user interface (UI).

3. ProviderContainer: A container for storing each provider's current values. It enables you to read and alter the state that the providers have provided.

4. Family: A method of constructing providers that rely on a key or parameter. When you require many instances of a provider based on various parameters, it is helpful.