flutter_bloc_extensions 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

flutter_bloc_extensions #

pub package

Collection of helper objects built on top of awesome library by Felix Angelov flutter_bloc : https://github.com/felangel/bloc/

Features #

  1. BlocProjectionBuilder A Flutter widget slightly more powerful than BlocBuilder. The main difference is the additional converter parameter which is responsible for listening on changes only on the subset of the state. This can bring some performance benefits since each widget can listen only to the relevant part of the bloc state and the number of widget rebuilds can be greatly reduced (in some cases).

  2. DisposableBlocProvider A simple wrapper widget around BlocProvider which also handles calling the dispose method on the bloc. Bloc must be created using blocFactory parameter so you can create the bloc directly inside the build function of parent widget and prevent multiple instances to be created on each build.

More features like special purpose blocs for loading data with progress indicator or bloc suitable for complex forms with many states coming soon....

Why does this exist? #

While developing apps with flutter_bloc library I came up with a bunch of bloc-related general purpose objects. Those objects are often useful only in special use cases so it doesn't make much sense to have them in the original library. For more info why this library was created see this thread: https://github.com/felangel/bloc/issues/174

Usage #

BlocProjectionBuilder #

Example of the builder listening only to the single value from the state. It won't be rebuild every time new state is emitted but only when this value is changed:

BlocProjectionBuilder<LoginEvent, LoginState, bool>(
    bloc: bloc,
    converter: (state) => state.hasAgreed,
    builder: (context, hasAgreed) {
        return RaisedButton(
            onPressed: hasAgreed ? () => _showDialog(context) : null,
            child: Text("Login"),

Converter doesn't have to return just single value as in the example above, it can be more complex custom object composed of multiple properties from the bloc:

converter: (state) => 
    MyViewModel(property1: state.property1, property2: state.property2),

In order for this to work correctly, you must implement == and hashCode in your ViewModel so the builder will correctly detect when your ViewModel has changed.

DisposableBlocProvider #

Whenever you create a bloc instance you are also responsible for disposing it. Good rule of thumb is to dispose it in the same place/widget where you created it. BlocProvider is not responsible for disposing your bloc object because it could be surprising behavior for many users. That's why DisposableBlocProvider exists. Its name already indicates that the bloc will be disposed together with the DisposableBlocProvider widget.

//Inside build method
    blocFactory: () => MyBloc(),
    child: MyPage(),

//Inside MyPage
Widget build(BuildContext context) {
    var bloc = BlocProvider.of<MyBloc>(context);

Since DisposableBlocProvider creates BlocProvider under the hood you can retrieve the instance via BlocProvider.of as you would do with regular BlocProvider.

0.1.2 #

Updated to flutter_bloc: ^0.13.0

0.1.1 #

Minor readme and code formatting fixes

0.1.0 #

Initial Version of the library.

  • Includes BlocProjectionBuilder widget
  • Includes DisposableBlocProvider widget


example #

Flutter bloc extensions example project

Use this package as a library

1. Depend on it

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

  flutter_bloc_extensions: ^0.1.2

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:flutter_bloc_extensions/flutter_bloc_extensions.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 Feb 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.8

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (flutter_bloc).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_bloc ^0.13.0 0.13.0 3.2.0
Transitive dependencies
bloc 0.13.0 3.0.0
collection 1.14.11 1.14.12
meta 1.1.8
rxdart 0.22.6 0.23.1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies