bloc_streambuilder 0.3.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 58

bloc_streambuilder #

A stream builder that uses the value of a ValueObservable as initial data. This builder in combination with ValueSubject makes sure that the streambuilder does not need to build twice when the stream already has a value.

Example #

     ValueObservable<int> stream = ValueSubject(seedValue: 0);

       builder: (context, snapshot) { // Only called once and immediately with data if the stream has data

             "Build called with data: ${}, connectionState: ${snapshot.connectionState}"
         ); // First time it prints "Build called with data: 0, connectionState:"

         return new Text('${}');
       stream: stream,

[0.3.2] - 17 November 2018

Added a readme for the example

[0.3.1] - 17 November 2018

Updated the changelog

[0.3.0] - 17 November 2018

Breaking change: switched to using rxdart Subject and ValueObservable

[0.2.0] - 17 November 2018

Improved interface of the library

[0.1.0] - 16 November 2018

Initial release


A simple example #

This example show how you can make the simple counter app with the library. It also shows a comparison to what it intends to fix.

It uses the BLOC pattern.

The build method of the page #

In this build method we see that using an inherited widget the bloc is retrieved. It is then used for displaying the counter and handling the buttons

  Widget build(BuildContext context) {
    var bloc = BlocProvider.of(context);
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(title),
        leading: IconButton(
          icon: Icon(Icons.restore_page),
          onPressed: () => bloc.buttonPress.add(CounterPageButton.reset),

			builder: (context, snapshot) {
				"Value build called with data: ${}, connectionState: ${snapshot.connectionState}");
			return new Text(
				style: Theme.of(context).textTheme.display1,
			stream: bloc.counterValue,

      floatingActionButton: new FloatingActionButton(
        onPressed: () => bloc.buttonPress.add(CounterPageButton.add),
        tooltip: 'Increment',
        child: new Icon(Icons.add),

The bloc #

This bloc has a single stream (ValueObservable) and a single sink. The sink is simply using the built in dart StreamController. But the stream uses the new ValueSubject class which handles keeping track of the value.

class Bloc {
  final _counterValueSubject = ValueSubject<int>(seedValue: 0, distinct: true);
  ValueObservable<int> get counterValue => _counterValueSubject;

  final _buttonPressController = StreamController<CounterPageButton>();
  Sink<CounterPageButton> get buttonPress => _buttonPressController;

  Bloc() {;

  void _pressedButton(CounterPageButton button) {
    switch (button) {
      case CounterPageButton.add:
        _counterValueSubject.value += 1;
      case CounterPageButton.reset:
        _counterValueSubject.value = 0;

Use this package as a library

1. Depend on it

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

  bloc_streambuilder: ^0.3.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:bloc_streambuilder/bloc_streambuilder.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 Jan 20, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

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 (rxdart).

Package is getting outdated. (-17.26 points)

The package was last published 61 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
rxdart >=0.19.0 <0.20.0 0.19.0 0.23.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies