yaz
Yaz Package for State, Content and User's Options Managements
This package is supported for Web, Mobile and Desktop applications.
Yaz Package is consisted of two parts;
1) State Management
-
Yaz Package is a state management package in the first place. It uses only
ChangeNotifier
for the whole process, due to this it is really simple and fast.
It uses only one widget. Widget of "YazListenerWidget" -
Yaz helps you to convert any objects to
ChangeNotifier
with a simple code. -
Yaz supports for collection changes both in separate or entirely.
2) Content Management
-
Yaz provides you to get and change user options by a simple code from any part of the application.
-
Yaz helps you to store and cache your app's Frequently Used Contents.
Example of Flutter Counter App
Usage
How to Convert an Object to a Change Notifier?
Any object might be converted into a ChangeNotifier
: YazNotifier
.notifier
works on any object and returns a YazNotifier
.value
gets and set an value in YazNotifier
instance;
This setter triggers all listeners
! Attention:
If you wish to listen changes in instance members of foo
:
Because foo
is triggered only like this;
BuiltNotifier
You can see the widgets wrapped by BuiltNotifier
when they are rebuilt. They blink when they are rebuilt.
YazListenerWidget
YazListenerWidget
works with any ChangeNotifier
instance. There is no other widget for state management.
Also you can create YazListenerWidget
instance by .builder
method works on any ChangeNotifier
s.
! Performance Tip:
Narrow down this widget as narrow as possible. Using more YazListenerWidget
s is better than using a single widget to wrap all things.
Single Variable
Multiple Variable
How to listen collection changes?
There are 3 ways to listen collections
1) Classical Total Changes - Bad Way
In this way, standard .notifier
is used
But this triggers only like this;
2) Triggering in any changes - Mid-Way
In this way, a YazList is created.
A YazList
can be created by .listenAll
from all List
instances.
YazMap
can be created from all Map
s by this way, as well.
YazList
is a ChangeNotifier
and all listeners are triggered in any changes.
3) Trigger every element separately - Good Way
You can get a List<YazNotifier>
on any List
by .listeners
method.
In this way, value
changes of elements trigger all listeners
When making length-changings like adding or removing elements or making YazNotifier
instance changes; listeners are NOT triggered.
For instance, let us assume that there are two separate widgets to listen index of 0 and index of 1.
When index of 0 is changed, only the widget of 0 is rebuilt.
Other one is not rebuilt.
To trigger all changes, .notifyAll
method on List<YazNotifier>
may be used.
All can be applied on Map
.
You can get a Map<K, YazNotifier<V>>
by .listeners
on Map
.
How to listen Stream?
All streams convertible by .yazStream
or .yazStreamWithDefault(value)
on Stream
.yazStream
returns nullable YazStream<T?>
.yazStreamWithDefault(value)
returns non-nullable YazStream<T>
User Options
Simple Example
You can manage every user option by this service.
Usage
You can get option in everywhere:
and you change
You can wrap your widgets with options, when options are changed the widgets are rebuilt;
You can init by your default values;
You can listen changes for to fetch on db
If you don't use init functions, you may set default values in the first use.
You don't have to set default values for your further uses in session flow.
Content Controller
You can store or cache your common uses contents.
For example: Friend users, e-commerce categories eg.
Just! you will get content with their identifier.
You don't need a second query from db to recall content repeatedly.
However, if the content is too old, it will be restored from db.
Usage
Implement CacheAble
Your cache able class must have a unique identifier.
Implement your controller
There are two kind content controller:
- CacheContentController : Store contents only session
- StorageContentController : Store contents in device key-value storage
Also you can inititialize with your unordered contents
Save , update or remove content
But many cases you dont need this. Because if you determine max's carefully,
getContent
do these for you.