A compilation of commented Flutter starter incrementer app examples, that uses BLoC.
-
Local Instance: This example uses a plain local instance, which can be good enough for some situations.
final incrementBloc = IncrementBloc();
-
Ancestor Provider as Stateful Widget: A generic bloc provider (code by Didier Boelens) can instantiate any BLoC that implements the provider. It can then be accesed like:
IncrementBloc incrementBloc = BlocProvider.of<IncrementBloc>(context);
The examples were done thanks to the fantastic explanation from these articles:
- Filip Hracek: Build reactive mobile apps in Flutter — companion article
- Didier Boeledi: Reactive Programming - Streams - BLoC