omarokasha1 / TheFirstProject

This is a Learning Management System Solutions Developed from Scratch inside Orange Digital Center Labs By ODC-Flutter WorkForce.
https://www.orangedigitalcenters.com/country/EG/home
10 stars 6 forks source link

Learning Process: State Management (Riverpod) #7

Open mirette3 opened 2 years ago

mirette3 commented 2 years ago

Advantages

youssefelgebaly commented 2 years ago

N|Solid

Riverpod

A state-management library that:

Build Status Build Status Build Status

package name description
Build Status Allows using both flutter_hooks and Riverpod together.
Build Status A basic way of using Riverpod for Flutter applications
Build Status A version of Riverpod with all the classes related to Flutter stripped out.

For widgets to be able to read providers, we need to wrap the entire application in a "ProviderScope" widget.

void main() {
  runApp(ProviderScope(child: MyApp(),),);
}

Providers

Providers are the most important part of a Riverpod application. A provider is an object that encapsulates a piece of state and allows listening to that state.

Creating a provider

final myProvider = Provider((ref) =>MyValue());

in Riverpod we can have two providers expose a state of the same "type":

final cityProvider = Provider((ref) => 'London');
final countryProvider = Provider((ref) => 'England');

Provide data:

mariamyoussefwiliam commented 2 years ago

Riverpod

to Installing this package

dependencies:
  riverpod: ^last_version

Import it

import 'package:riverpod/riverpod.dart';

Type of Provider

Advantages of RiverPod