Presenter Sagar Koju A state is a piece of information held by a widget when built and can change when the widget refreshes Certain data or information stored and passed across or within the widgets in an application is referred to as the state ID: 933207
Download Presentation The PPT/PDF document "INTRODUCTION TO RIVERPOD" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
INTRODUCTION TO RIVERPOD
Presenter: Sagar
Koju
Slide2A state is a piece of information held by a widget when built, and can change when the widget refreshes.Certain data or information stored and passed across or within the widgets in an application is referred to as “the state.”
State management refers to the techniques or methods used to handle the state in an application.
Slide3INTRODUCTIONState Management System which fixes some of the limitation of provider that has.Invented by Remi
Rousselet
Compile time Safe, and does not depend on flutter without build context
Support for multiple provider of the same type combining asynchronous provider
Slide4Use ProviderScope as a root widget.Comes from Three flavor: 1. riverpod(dart)
2.
flutter_riverpod
(Flutter)
3.
hook_riverpod
(Flutter + hook package)
Slide5Comparing Provider and RiverpodRuntime exceptions exist with Provider, but they are handled and corrected with
Riverpod
Provider is not compile-safe while
Riverpod
is
In Provider you can’t declare multiple providers of the same type, while in
Riverpod
, you can do this without overriding the others
In
Riverpod
, the providers are declared globally and can be used anywhere in the app using either
the Consumer Widget or
context.read
Slide6Common Provider Used in Riverpod1. Provider<T>: read only value inside the widget
Simple type of Provider mostly used in sharing the data.
final
valueProvider
= Provider<
int
>((ref) { return 36;
});
Does not change the value
2.
StateProvider
<T>: Expose the value to the Outside of Widget.
Similar to the
ChangeNotifierProvider
.
final
counterStateProvider
=
StateProvider
<
int
>((ref) { return 0; });
Slide73. ProviderListener: Used to push the route, show dialog or snackbar when the state change.
equivalent of
BlocListener
from the
flutter_bloc
package
.
4. State Notifier: State is immutable
Automatically UI refresh.
Not Changeable outside the class.
5. Change Notifier : State is mutable
Manually UI refresh.
Changeable outside the class
Slide8Fig: Business logic of State Notifier
Slide9watch the model's state and rebuild when it changes.call methods in your model classes (using context.read<Model>
which in turn can update the state and (optionally) interact with external services.
Slide106. Future Builder and Stream Builder : work with asynchronous code.can rebuild our UI when some asynchronous data changes
.
We get
AsyncValue
<T> when we watch these provider which is a type that comes from the
freezed
package
we can use
the when()
method to map the
data
,
loading
, and
error
states to different widgets
Slide11When to Use Watch and Read Method Watch method is using for combining the multiple provider
Watch method is used
every time we needed to read the value of a provider inside
a build method
read method is used
inside button callbacks or callback handlers.
Slide12Fig:
Riverpod
graphical illustration
Slide13THE END