bloc_streambuilder 0.3.2

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

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);

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

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

         return new Text('${snapshot.data}');
       },
       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

example/README.md

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

 @override
  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),
        ),
      ),
		...

		ValueObservableBuilder(
			builder: (context, snapshot) {
			print(
				"Value build called with data: ${snapshot.data}, connectionState: ${snapshot.connectionState}");
			return new Text(
				'${snapshot.data}',
				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() {
    _buttonPressController.stream.listen(_pressedButton);
  }

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

Use this package as a library

1. Depend on it

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


dependencies:
  bloc_streambuilder: ^0.3.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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:bloc_streambuilder/bloc_streambuilder.dart';
  
Version Uploaded Documentation Archive
0.3.2 Nov 17, 2018 Go to the documentation of bloc_streambuilder 0.3.2 Download bloc_streambuilder 0.3.2 archive
0.3.1 Nov 17, 2018 Go to the documentation of bloc_streambuilder 0.3.1 Download bloc_streambuilder 0.3.1 archive
0.3.0 Nov 17, 2018 Go to the documentation of bloc_streambuilder 0.3.0 Download bloc_streambuilder 0.3.0 archive
0.2.0 Nov 17, 2018 Go to the documentation of bloc_streambuilder 0.2.0 Download bloc_streambuilder 0.2.0 archive
0.1.0+2 Nov 16, 2018 Go to the documentation of bloc_streambuilder 0.1.0+2 Download bloc_streambuilder 0.1.0+2 archive
0.1.0+1 Nov 16, 2018 Go to the documentation of bloc_streambuilder 0.1.0+1 Download bloc_streambuilder 0.1.0+1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test