Flutter BLoC Widget

Flutter BLoC Widget is an experimental Flutter package that provides a new way to build widgets in Flutter applications using the BLoC (Business Logic Component) pattern. This package allows developers to extend the BlocWidget class instead of the traditional Stateful or Stateless widgets, making it easy to separate the UI from the business logic of the application.

With the Flutter BLoC Widget package, developers can write a separate BLoC class that manages the application state and logic, and then use the BlocWidget class to build the UI based on the state of the BLoC. The package also includes some additional features, such as automatic initialization of the BLoC and handling of errors and loading states.

Please note that this package is still experimental and should be used with caution. It is subject to changes and improvements, and may not be suitable for production use yet. Nonetheless, it provides an exciting new approach to building widgets in Flutter that developers may find useful in their projects.

style: very good analysis Powered by Mason License: MIT

Installation ๐Ÿ’ป

โ— In order to start using Flutter Bloc Widget you must have the Flutter SDK installed on your machine.

Add flutter_bloc_widget to your pubspec.yaml:

dependencies:
  flutter_bloc_widget:

Install it:

flutter packages get

Usage

To use the package, extend the BlocWidget class and implement the build method, which will be called whenever the BLoC's state changes. Here's an example:

class MyWidget extends BlocWidget<MyBloc, MyState> {
  const MyWidget({Key? key}) : super(key: key);

  @override
  final MyBloc blocInitializer => MyBloc();

  @override
  Widget build(BuildContext context, MyBloc bloc, MyState state) {
    // Build the UI based on the state of the BLoC
  }
}

class MyBloc extends Bloc<MyEvent, MyState> {
  // Implement the BLoC's state and event mapping
}

Continuous Integration ๐Ÿค–

Flutter Bloc Widget comes with a built-in GitHub Actions workflow powered by Very Good Workflows but you can also add your preferred CI/CD solution.

Out of the box, on each pull request and push, the CI formats, lints, and tests the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses Very Good Analysis for a strict set of analysis options used by our team. Code coverage is enforced using the Very Good Workflows.


Running Tests ๐Ÿงช

For first time users, install the very_good_cli:

dart pub global activate very_good_cli

To run all unit tests:

very_good test --coverage

To view the generated coverage report you can use lcov.

# Generate Coverage Report
genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
open coverage/index.html

Libraries

flutter_bloc_widget
My new Flutter package