A flutter app to showcase online shopping portal using Provider
architecture. FireStore
has been used as backend for this app.
Among multiple state management in flutter, Provider
is now more powerful, flixible and easy to undersand. It has the power of managing state in efficient manager by using Consumer
and Selector
and now it can deals with Stream
and Future
also.
A mixture between dependency injection (DI) and state management, built with widgets for widgets.
It purposefully uses widgets for DI/state management instead of dart-only classes like Stream
. The reason is, widgets are very simple yet robust and scalable.
By using the power of provider we can make our own provider. Provider
expose all the small components that makes a fully fledged provider.
Provider
includes below widgets for customizability:
SingleChildCloneableWidget
, to make any widget works withMultiProvider
.InheritedProvider
, the genericInheritedWidget
obtained when doingProvider.of
.DelegateWidget
/BuilderDelegate
/ValueDelegate
to help handle the logic of "MyProvider() that creates an object" vs "MyProvider.value() that can update over time".
- UI logic and business logic are clearly separated
- Provider is customizable and gives flexibility to customize provider according to your need to boost the performance and stability.
- Easy to understand and implement
- Can be set up with unidirectional data flow without much difficulty, gaining the main benefit of Redux as well as provider is more powerful to handle global state.
- Robustness, as it is harder to forget to handle the update scenario of a model/widget
provider
exposes a few different kinds of "provider" for different types of objects.
The complete list of all the objects available is here
name | description |
---|---|
Provider | The most basic form of provider. It takes a value and exposes it, whatever the value is. |
ListenableProvider | A specific provider for Listenable object. ListenableProvider will listen to the object and ask widgets which depend on it to rebuild whenever the listener is called. |
ChangeNotifierProvider | A specification of ListenableProvider for ChangeNotifier. It will automatically call ChangeNotifier.dispose when needed. |
ValueListenableProvider | Listen to a ValueListenable and only expose ValueListenable.value . |
StreamProvider | Listen to a Stream and expose the latest value emitted. |
FutureProvider | Takes a Future and updates dependents when the future completes. |
To read more about provider
, see the documentation.