eventizer 0.1.1 eventizer: ^0.1.1 copied to clipboard
transform your flutter package with eventizer for asynchronous state management
Eventizer #
Eventizer will help you in decoupling of your ui code and logic code. with eventizer you have single link between all ui element and logic element. it will also help in modular architecture.
Event Widget Usage #
-
Wrap a dynamic widget in
EventWidget
with the help ofbuilder
e.g.EventWidget( builder: (context, widget, event) => Text('${event.get<int>()}'), ),
-
Then specify events this widget will capture and test using
consumers
.consumers
is a Map structure withEventID
as key and a tester Function as value. whenever event withEventID
is fired this widget will catch it and execute tester function. if tester return true Widget will rebuild. e.g.consumers: {someEventID: testFunction(event)},
-
Then Whenever and Wherever you need to rebuild above Widget. You just need to fire the event with or without data e.g.
someEventID.fireWith(data);
Aditionals #
-
Above
EventWidget
will drawSizedBox.shrink()
in release mode andText('Empty Widget')
in debug mode till a event id fired. but what if we need something prior to loading. There are multiple ways to handle thischildPlaceHolder
property will be returned if no event has been captured yet and it.child
will be returned ifchildPlaceHolder
is null and no event has been captured yet- you can even specify
buildEvent
. then EventWidget will be initialized as if it has captured passedbuildEvent
.
-
Flutter rebuild is not instantaneous but scheduled. So it might be possible event just added will miss a fast event. in this case you can start your task just after
EventWidget
is built usingonReady
Callback property.
Event #
There are multiple ways data is encapsulate in an event object
Event
is fired without any data usingevent.fireWith()
. most suitable for notifications.Event
if fire with single data object usingevent.fireWith(data)
. In this case you can extract data simply by usingevent.get()
.Event
is fired with List of data, preferable of unique type, usingevent.fireWith([data1,data2,...])
. In this case you can extract data from event usingevent.get<type>(id)
.Event
is fired with List of data, preferable of unique type, usingevent.fireWith({key1:value1,key2,value2})
. In this case you can extract data from event usingevent.get<type>(key)
.
note: type parameter is optional in above APIs