built_bloc 0.3.3

  • README.md
  • Example
  • Installing
  • Versions
  • 68

built_bloc #

Helper class for adopting the BLoC pattern, alongside with a few annotations to use in combination with built_bloc_generator (which is stongly recommended).

Quickstart #

Simply extends from Bloc and add your subjects and subscriptions.

class ExampleBloc extends Bloc {
  Sink<int> get add => this._add.sink;

  Stream<int> get count => this._add.stream;

  final PublishSubject<int> _add = PublishSubject<int>();

  final BehaviorSubject<int> _count = BehaviorSubject<int>.seeded(0);

  ExampleBloc() {
    this.subjects.addAll([_add, _count]);
    this.subscriptions.addAll([ _add.listen(_onAdd) ]);
  }

  void _onAdd(int value) {
    this._count.add(this._count.value + 1);
  }
}

How to use #

Install #

dependencies:
  built_bloc:

example/example.dart

import 'dart:async';

import 'package:built_bloc/built_bloc.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';

class ExampleBloc extends Bloc {
  Sink<int> get add => this._add.sink;

  Stream<int> get count => this._add.stream;

  final PublishSubject<int> _add = PublishSubject<int>();

  final BehaviorSubject<int> _count = BehaviorSubject<int>.seeded(0);

  ExampleBloc() {
    this.subjects.addAll([_add, _count]);
    this.subscriptions.addAll([ _add.listen(_onAdd) ]);
  }

  void _onAdd(int value) {
    this._count.add(this._count.value + 1);
  }
}

/// As a comparison, here would have been the class written with
/// pure vanilla code.
class VanillaExampleBloc {

  Sink<int> get add => this._add.sink;

  Stream<int> get count => this._add.stream;

  final PublishSubject<int> _add = PublishSubject<int>(sync: true);

  final BehaviorSubject<int> _count = BehaviorSubject<int>.seeded(0, sync: true);

  List<StreamSubscription> subscriptions;

  List<Subject> subjects;

  VanillaExampleBloc() {
    subscriptions = [
      this._add.listen(_onAdd),
    ];
    subjects = [
      this._add,
      this._count,
    ];
  }

  void _onAdd(int value) {
    this._count.add(this._count.value + 1);
  }

  @mustCallSuper
  void dispose() {
    this.subjects.forEach((s) => s.close());
    this.subscriptions.forEach((s) => s.cancel());
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  built_bloc: ^0.3.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:built_bloc/built_bloc.dart';
  
Version Uploaded Documentation Archive
0.3.3 Mar 21, 2019 Go to the documentation of built_bloc 0.3.3 Download built_bloc 0.3.3 archive
0.3.2 Mar 1, 2019 Go to the documentation of built_bloc 0.3.2 Download built_bloc 0.3.2 archive
0.3.1 Feb 22, 2019 Go to the documentation of built_bloc 0.3.1 Download built_bloc 0.3.1 archive
0.3.0 Feb 22, 2019 Go to the documentation of built_bloc 0.3.0 Download built_bloc 0.3.0 archive
0.2.13 Jan 31, 2019 Go to the documentation of built_bloc 0.2.13 Download built_bloc 0.2.13 archive
0.2.13-dev Jan 29, 2019 Go to the documentation of built_bloc 0.2.13-dev Download built_bloc 0.2.13-dev archive
0.2.12-dev Jan 28, 2019 Go to the documentation of built_bloc 0.2.12-dev Download built_bloc 0.2.12-dev archive
0.2.11-dev Jan 28, 2019 Go to the documentation of built_bloc 0.2.11-dev Download built_bloc 0.2.11-dev archive
0.2.10-dev Jan 25, 2019 Go to the documentation of built_bloc 0.2.10-dev Download built_bloc 0.2.10-dev archive
0.2.9-dev Jan 25, 2019 Go to the documentation of built_bloc 0.2.9-dev Download built_bloc 0.2.9-dev archive

All 25 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

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

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:built_bloc/built_bloc.dart.

Health suggestions

Fix lib/src/annotations/bloc_stream.dart. (-1 points)

Analysis of lib/src/annotations/bloc_stream.dart reported 2 hints:

line 2 col 16: The class 'Stream' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 4 col 34: The class 'Stream' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/annotations/bind.dart. (-0.50 points)

Analysis of lib/src/annotations/bind.dart reported 1 hint:

line 1 col 59: The class 'Stream' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Format lib/built_bloc.dart.

Run dartfmt to format lib/built_bloc.dart.

Format lib/src/bloc.dart.

Run dartfmt to format lib/src/bloc.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
meta ^1.1.6 1.1.7
rxdart ^0.21.0 0.21.0