bloc_library/README.md
This sample makes use of the bloc, flutter_bloc, and bloc_test libraries to manage state.
Check out the bloc library documentation for more details and tutorials.
BlocProvider at the greatest common ancestorEvents are the input to a bloc.
States are the output of a bloc and represent a part of your application's state.
Transition.
Transition consists of the current state, the event, and the next state.Stream of incoming Events into a Stream of outgoing StatesEvery bloc has an add method. Add takes an event and triggers mapEventToState. Add notifies the bloc of a new event which will then trigger a state change.
In this implementation, the FilteredTodosBloc depends on the TodosBloc and will update the list of filtered todos in response to changes in the TodosBloc.
This approach demonstrates how we can build a reactive application by composing blocs from other blocs. On app start, the TodosBloc is hydrated with todos from the repository and from that moment forward, all mutations to todos are executed through the TodosBloc which persists the changes asynchronously. The FilteredTodosBloc listens for changes in the TodosBloc state and will update it's list of filtered todos. The result is, a hierarchy of states with all todos being managed by the TodosBloc and a subset of those todos (filtered todos) being managed by the FilteredTodosBloc.
BlocBuilder is a Flutter widget which requires a bloc and a builder function. BlocBuilder handles building the widget in response to new states. BlocBuilder is very similar to StreamBuilder but has a simplified API to reduce the amount of boilerplate code needed and is also optimized to avoid unnecessary rebuilds.
Generally, this app conforms the "Testing Pyramid": Lots of Unit tests, fewer Widget tests, and fewer integration tests.
Blocs can easily be tested by mocking dependencies with Mockito. Events can be added and we can assert that the blocs' state has changed correctly.flutter drive --target test_driver/todo_app.dart.