BLoCs for Flutter made easy.
Write the Code you need with as minimal Boilerplate as possible
Feel at Home
Be usefull everywhere, even in now-unknown places
Yo dawg, I heard you like Blocs, so I put some Blocs in your Blocs, so now you can play Tetris while playing Tetris
(soon)
An Event happening in your App, originating by UI or somewhere else. TetrisEvents are fully described by
- String action The action you expect to happen
- String type Optional Type of event
- dynamic payload Any type of Object you want to process
A TetrisBloc is an asynchronous Event Processor. It handles events sourced through
MyTetrisBloc.dispatch(TetrisEvent.withAction(action:"MyAction"));
in its
Stream<TetrisEvent> processEvent(TetrisEvent event)
function and yields a (new) event as a result.
TetrisProvicer is a DI Container that provides instances of your TetrisBloc's to Widgets in your App.
A Provider can hold multiple BLoCs and you can have multiple Providers in your App.
To retrieve a BLoC from the Provider call
var bloc = TetrisProvider.of<MyBloc>(context)
TetrisBuilder is similar to StreamBuilder in that it will rebuild your Widgets on incoming TetrisEvents A Single Builder can receive Events from multiple BLoCs. It has a withFilter Constructor that allows you to drop Events that are not of interest.
TetrisBuilder.withFilter(
blocs: [myFirstBloc, mySecondBloc],
builder: (BuildContext context, TetrisEvent event) { return Text(event.action) },
filter: (TetrisEvent event){ return event.action == "accept"; }
);
With Simplicity in Mind, loading a List is down to two lines of code. To Trigger the Action:
TetrisProvider.of<MyTetrisBloc>(context).dispatch(TetrisEvent.withAction("loadList")
And the full implementation of the Bloc is this:
class MyTetrisBloc extends TetrisBloc {
Stream<TetrisEvent> processEvent(TetrisEvent event) async* {
yield TetrisEvent.withPayload("loadList",[1,3,5,7]);
}
}
The classic "Button Clicker" Example is here
- @dividebyzero
- Your name here ?