flutter_bloc_extensions 0.1.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 77

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
DisposableBlocProvider(
    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/README.md

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:


dependencies:
  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';
  
Version Uploaded Documentation Archive
0.1.2 May 12, 2019 Go to the documentation of flutter_bloc_extensions 0.1.2 Download flutter_bloc_extensions 0.1.2 archive
0.1.1 Apr 11, 2019 Go to the documentation of flutter_bloc_extensions 0.1.1 Download flutter_bloc_extensions 0.1.1 archive
0.1.0 Apr 11, 2019 Go to the documentation of flutter_bloc_extensions 0.1.0 Download flutter_bloc_extensions 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Jun 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (1 direct: flutter_bloc).

Dependencies

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 0.17.0
Transitive dependencies
bloc 0.13.0 0.14.2
collection 1.14.11
meta 1.1.6 1.1.7
rxdart 0.22.0
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test