Flutter BLoC Library

BLoC Layers

  • UI/Presentation Layer

  • Business Logic Layer

  • Data Layer

    • Repository

    • Data Provider

  • BlocListener : BlocListener is a Flutter widget which takes a BlocWidgetListener and an optional Bloc and invokes the listener in response to state changes in the bloc. It should be used for functionality that needs to occur once per state change such as navigation, showing a SnackBar, showing a Dialog, etc.

  • BlocBuilder : BlocBuilder is very similar to StreamBuilder but has a more simple API to reduce the amount of boilerplate code needed. The builder function will potentially be called many times and should be a pure function that returns a widget in response to the state.

  • BlocProvider : BlocProvider is a Flutter widget which provides a bloc to its children via BlocProvider.of<T>(context). It is used as a dependency injection (DI) widget so that a single instance of a bloc can be provided to multiple widgets within a subtree.

  • BlocObserver : Observe all the state from a central place, it can handle or intercept changes, can deal exception from that place.