washington 0.0.1-dev.1 washington: ^0.0.1-dev.1 copied to clipboard
A Global Event Driven State Management package for Flutter.
The Non-Nonsense Event Driven State Management solution for Flutter.
Washington #
Washington
is the capitol of your state management. You will use Washington
to dispath
events for your application.
Washington.instance.dispatch(SomeEvent());
UnitedStates #
You use UnitedState
objects to manager your application's state
.
To create these objects, all you have to do is extend the UnitedState
class and add handlers for all the events you want your UnitedState
to act upon.
Each UnitedState
should be responsible for a specific area of your app. For example, you could have a UserState
, ProductsState
and SettingsState
.
sample:
class UserState extends UnitedState<User?> {
UserState() : super(null) {
addHandler<Login>((event) => ... );
addHandler<Logout>((event) => ... );
...
}
}
Events #
An event can be any object you want. You use Washington
to dispatch these events. Washington
will make sure that the events reach all the UnitedState
s so they can do their thing.
Because you can dispatch anything as an event, you are able to dispatch events that can be handled by multiple states at the same time.
You can dispatch a UserLogout
event and the UserState
can act upon this. But the SettingsState
could also use this event to clear all the user's preferences.
Widgets #
To use Washington
in your Flutter application you can use a set of conviniet widgets that help you build or trigger UI elements based on events and state changes.
StateProvider #
States can be scoped in the widget tree by using StateProvider
s.
When you need to add multiple StateProvider
s add the same level, considder using
a MultiStateProvider
. This makes your code more readable.
StateBuilder #
To build the UI based on the current state you can use StateBuilder
.
...
Statelistener #
When you need to trigger one-off actions (like navigating or showing a snackbar) based on state changes, you can use the StateListener
.
...
EventListener #
If you want to trigger one-off actions based on the events being dispatched, instead of a state change, you can use the EventListener
.
...