flutter_stream_redux 0.0.4+1

  • README.md
  • Example
  • Installing
  • Versions
  • new58


Stream helper for build_redux and flutter_build_redux

Getting Started with StreamMiddleware

Add action

In you action file add the action that you want to trigger the stream subscription. The payload of this action should be of type SubscriptionPayload. The type of SubscriptionPayload should be the type of payload you want to receive in the getStream method in the MiddlewareStreamHandler. It can also be of type Null if you don't want to receive anything. In the example we have a payload type of Duration witch is the interval at witch we emit a new value:

ActionDispatcher<SubscriptionPayload<Duration>> get timeStream;

Create the stream middleware

Create middleware

We can create the the middleware using the MiddlewareStreamBuilder and add the actions you've created on the previous step. Note that only actions with the payload type of SubscriptionPayload are accepted.

Middleware<AppState, AppStateBuilder, AppActions> getStreamMiddleware() {
  final MiddlewareStreamBuilder<AppState, AppStateBuilder, AppActions> builder =
      new MiddlewareStreamBuilder<AppState, AppStateBuilder, AppActions>();

  builder..add(AppActionsNames.timeStream, new TimeStreamHandler());

  return builder.build();

Add you action handler class

To handle the middleware action you need to create a class that extends MiddlewareStreamHandler<AppState, AppStateBuilder, AppActions, Payload, StreamType>.

The Payload is the type of the SubscriptionPayload<Payload> object you've added in the first step. In getStream you receive the payload you've passed when you called the triggering action.

The StreamType is the type of the object you stream produces, like Stream<StreamType>.

In the getStream method you need to return the stream you want to listen to. onData is called each time a new value was emitted. You can also handle errors and stream close using the other callbacks. You can also chose to cancel the stream on error by overriding the cancelOnError field, default is false.

class TimeStreamHandler extends MiddlewareStreamHandler<AppState, AppStateBuilder, AppActions, Duration, int> {
  static final Log log = new Log('TimeStreamHandler');

  Stream<int> getStream(Duration payload) {
    //initialize your stream here

  void onData(MiddlewareApi<AppState, AppStateBuilder, AppActions> api, ActionHandler next,
      Action<SubscriptionPayload<Duration>> action, int event) {
    //handle new data emited

  void onError(MiddlewareApi<AppState, AppStateBuilder, AppActions> api, dynamic error, StackTrace stackTrace) {

  void onDone(MiddlewareApi<AppState, AppStateBuilder, AppActions> api) {
  bool get cancelOnError => false;

Add the stream middleware to your store

You just add you stream middleware to you middleware list of your Store.

  final Store<AppState, AppStateBuilder, AppActions> store = new Store<AppState, AppStateBuilder, AppActions>(
    new AppState.initialState(),
    new AppActions(),
    middleware: <Middleware<AppState, AppStateBuilder, AppActions>>[

Start listening to the stream.

To start listening to the stream you can now call the action you've create. When you subscribe you must give the payload you want to receive in getStream method in the MiddlewareStreamHandler. In this way you can manually subscribe and unsubscribe from the stream.



Getting Started with StreamedStoreConnector

If you want to remain subscribed to the stream as long as the Widget is on screen then you can use the StreamedStoreConnector<StoreState, Actions, LocalState, Payload> witch automatically manages the subscription for you. This is a thin wrapper around the StoreConnector from the flutter_built_redux package.

There are two more overrides to make this work.

streamAction is the action that triggers the subscription

subscribePayload is the payload you would normally pass to the subscription action. Payload is the type of the SubscriptionPayload

class NowStreamConnector extends StreamedStoreConnector<AppState, AppActions, int, Duration> {
  static final Log log = new Log('NowStreamConnector');

  NowStreamConnector({@required this.builder, @required this.duration});

  final ViewModelBuilder<int> builder;

  final Duration duration;

  Duration get subscribePayload => duration;

  ActionDispatcher<SubscriptionPayload<Duration>> streamAction(AppActions actions) => actions.timeStream;

  int connect(AppState state) => state.now;

  Widget build(BuildContext context, int now, AppActions actions) {
    return builder(context, now);

The logger package is https://pub.dartlang.org/packages/flutter_logger

[0.0.4] - Mar. 1, 2018

  • add type to Action in onData callback
  • add Middleware reference to onError and onDone callbacks
  • update the stream if the action or the subscription payload changes
  • add more content to README
  • add example

[0.0.3] - Feb. 28, 2018

  • BUGFIX: check if the handler is not null before trying to subscribe

[0.0.2] - Feb. 28, 2018

  • moved subscription to didChangeDependencies

[0.0.1] - Feb. 27, 2018

  • initial release.


import 'package:built_redux/built_redux.dart';
import 'package:example/automatic_stream_connection.dart';
import 'package:example/generated/i18n.dart';
import 'package:example/manual_stream_connection.dart';
import 'package:example/redux/actions.dart';
import 'package:example/redux/middleware.dart';
import 'package:example/redux/models/app_state.dart';
import 'package:example/redux/reducer.dart';
import 'package:example/redux/stream_middleware.dart';
import 'package:flutter/material.dart';
import 'package:flutter_built_redux/flutter_built_redux.dart' hide WidgetBuilder;
import 'package:flutter_localizations/flutter_localizations.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  final Store<AppState, AppStateBuilder, AppActions> store = new Store<AppState, AppStateBuilder, AppActions>(
    new AppState.initialState(),
    new AppActions(),
    middleware: <Middleware<AppState, AppStateBuilder, AppActions>>[

  _MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
  Widget build(BuildContext context) {
    return new ReduxProvider(
      store: widget.store,
      child: new MaterialApp(
        title: 'Stream Redux Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        supportedLocales: S.delegate.supportedLocales,
        localizationsDelegates: <LocalizationsDelegate<dynamic>>[
        home: const ManualStreamConnector(),
        routes: <String, WidgetBuilder>{
          'automatic': (BuildContext context) => const AutomaticStreamConnection(),

1. Depend on it

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

  flutter_stream_redux: "^0.0.4+1"

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_stream_redux/flutter_stream_redux.dart';
Version Uploaded Documentation Archive
0.0.4+1 Mar 1, 2018 Go to the documentation of flutter_stream_redux 0.0.4+1 Download flutter_stream_redux 0.0.4+1 archive
0.0.4 Mar 1, 2018 Go to the documentation of flutter_stream_redux 0.0.4 Download flutter_stream_redux 0.0.4 archive
0.0.3+1 Feb 28, 2018 Go to the documentation of flutter_stream_redux 0.0.3+1 Download flutter_stream_redux 0.0.3+1 archive
0.0.3 Feb 28, 2018 Go to the documentation of flutter_stream_redux 0.0.3 Download flutter_stream_redux 0.0.3 archive
0.0.2 Feb 28, 2018 Go to the documentation of flutter_stream_redux 0.0.2 Download flutter_stream_redux 0.0.2 archive
0.0.1 Feb 27, 2018 Go to the documentation of flutter_stream_redux 0.0.1 Download flutter_stream_redux 0.0.1 archive


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

  • Dart: 2.0.0-dev.31.0
  • pana: 0.10.3
  • Flutter: 0.1.7


Describes how popular the package is relative to other packages. [more]
17 / 100
Code health derived from static analysis. [more]
98 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.


  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix issues reported by dartanalyzer or dartfmt.

    dartanalyzer or dartfmt reported 4 hints.

    Run dartfmt to format lib/generated/i18n.dart.

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

    Similar analysis of the following files failed:

    • lib/src/streamed_store_connector.dart (hint)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0
built_collection ^3.0.5 3.0.5
built_redux ^7.4.0 7.4.0
built_value ^5.2.1 5.2.1
flutter 0.0.0
flutter_built_redux ^0.4.5 0.4.5 0.5.0
meta ^1.1.2 1.1.2
Transitive dependencies
analyzer 0.30.0+4 0.31.1
args 1.4.1
async 2.0.6
barback 0.15.2+14
boolean_selector 1.0.2
build 0.11.2 0.12.0+1
build_config 0.2.4
charcode 1.1.1
cli_util 0.1.2+1
collection 1.14.5
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.9+1 1.0.10
fixnum 0.10.7
front_end 0.1.0-alpha.4.1 0.1.0-alpha.10
glob 1.1.5
html 0.13.2+2
http 0.11.3+16
http_multi_server 2.0.4
http_parser 3.1.1
io 0.3.2+1
isolate 1.1.0
js 0.6.1
kernel 0.3.0-alpha.1.1 0.3.0-alpha.10
logging 0.11.3+1
matcher 0.12.1+4
mime 0.9.6
multi_server_socket 1.0.1
node_preamble 1.4.0
package_config 1.0.3
package_resolver 1.0.2
path 1.5.1
plugin 0.2.0+2
pool 1.3.4
pub_semver 1.3.2
quiver 0.28.0
shelf 0.7.2
shelf_packages_handler 1.0.3
shelf_static 0.2.7
shelf_web_socket 0.2.2
sky_engine 0.0.99
source_gen 0.7.5+1
source_map_stack_trace 1.1.4
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.2
stream_channel 1.6.4
string_scanner 1.0.2
term_glyph 1.0.0
typed_data 1.1.5
utf 0.9.0+4
vector_math 2.0.5
watcher 0.9.7+7
web_socket_channel 1.0.7
yaml 2.1.13
Dev dependencies
test ^0.12.0 0.12.31