mwb 1.0.1

  • Readme
  • Changelog
  • Installing
  • 78

Flutter package for the Model-Widget-BLoC (MWB) pattern.

This project contains a small set of classes and a sample project to demonstrate the MWB pattern, which is inspired by the Reactive Programming - Streams - BLoC article.

The actual library code is fairly small and only contains a few classes. The reason for this is that the MWB pattern shown in this repository is trying to keep things small and simple, but rich on possibilities to extend while being less dependant on libraries that dictate structure.

For further explanation of the pattern read the README of the sample project

General structure #

The idea is the same as with other state-management patterns: Separate the "responsability & ownership" for logic & data from UI classes.

MWB Pattern

  • Widget: Plain UI, straightforward Widgets that display something
  • BLoC: Business Logic Component. An abstract object that contains cached data/state and can execute business logic. This is where the access to the model classes happens.
  • Model: Anything that can act as a data source. That can be a DAO, or a class directing to REST endpoints or similar.

Library contents #

The library itself contains 3 classes: BlocProvider, BaseBloc, Instantiable.

Instantiables are objects with a lifecycle, similar to the one of a widget State. So every time you need an initialization and a destruction process you can implement this class.

BaseBlocs are derived from Instantiables. Their primary purpose is to mark classes explicitly as a Bloc which are used by the BlocProvider.

BlocProviders are widgets that are used to hold the instance of a bloc, manage it's lifecycle and provide that instance down the widget tree.

Bloc access #

In order to create a Bloc for a "widget tree scope" you'll have to wrap that widget inside a BlocProvider widget.

  bloc: MyPageBloc(),
  child: MyPage(),

You can then access the bloc instance by calling

_bloc = BlocProvider.of(context)

inside your widget/state (usually in initState). Casting is performed automatically.

1.0.1 #

* Moved sample project into separate folder
* Removed redundant initialization parameter from Instantiable class
* Updated documentation

1.0.0 #

* Initial release
* Setup sample application

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mwb: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mwb/bloc_provider.dart';
import 'package:mwb/instantiable.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart


  • mwb that is a package requiring null.

Maintenance suggestions

The package description is too short. (-11 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and mwb.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies