dynamic_middleware 0.5.1

  • README.md
  • Example
  • Installing
  • Versions
  • 50

Dynamic Middleware for Redux

Build Status

Dart library that allows adding and removing Redux middleware after a Redux Store has already been initialized.

Warning: Some might say that doing this breaks the contract of idempotency you typically have with a Redux store. They're right! There are, however, some instances where this is useful. This library was created to support a new type of Redux store that is not idempotent.


When creating your Redux Store simple attach a DynamicMiddleware object to it.

dynamicMiddleware = new DynamicMiddleware<State>.empty();
store = new Store<State>(reducer, middleware: [

Then add and remove middleware as you need.

dynamicMiddleware.add((store, action, next) => 
    print("Hello World!")

Use the DynamicMiddleware.fromSingle constructor to create new dynamic middleware with a single instance of Middleware.

store = new Store<State>(reducer, middleware: [
    new DynamicMiddleware.fromSingle(middleware1),

Use the DynamicMiddleware.fromList constructor to create new dynamic middleware from a List of Middleware.

waresList = <Middleware<State>>[middleware1, middleware2];
store = new Store<State>(reducer, middleware: [
    new DynamicMiddleware.fromList(waresList),

Adding and Removing Middleware

Add a single piece of middleware.

void add(Middleware<State> middleware);

Add a List of middleware.

void addAll(List<Middleware<State>> middleware) => middlewares.addAll(middleware);

Remove a single piece of middleware.

void remove(Middleware<State> middleware) => middlewares.remove(middleware);

Remove all middleware previously added.

void clear();





  • Update README.md


  • Adjust analysis_options.yaml rules.
  • Add empty and fromSingle constructors.
  • Follow the NextDispatcher pattern used by regular middleware.
  • Adjust tests and example to match updates.


  • Add toList() constructor and test it


  • Fix README.md


  • Add tests and example, Updated README.md


  • Initial version includes class DynamicMiddleware<State>


import 'dart:io';

import 'package:dynamic_middleware/dynamic_middleware.dart';
import 'package:redux/redux.dart';

/// Simple reducer that increments the state
int reducer(int state, Object action) => state+1;

/// Store that holds state value as an integer
Store<int> store;

/// Basic dynamic middleware object used to add and remove middleware
DynamicMiddleware<int> dynamicMiddleware;

/// Simple middleware that adds a line of standard output on all actions
void middleware(Store<int> store, Object action, NextDispatcher next) {
   stdout.writeln("Hello from dynamic middleware!");

void main() {
  dynamicMiddleware = new DynamicMiddleware<int>.empty();
  store = new Store<int>(reducer, initialState: 0, middleware: [dynamicMiddleware]);

  String input;
  while(input != "q") {
    stdout.writeln('Hit enter to dispatch an action,\nType "m" to dispatch an action with dynamic middleware,\nType "q" to quit');
    input = stdin.readLineSync();
    if(input == "m") {
        ..write("Counter: ")


Use this package as a library

1. Depend on it

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

  dynamic_middleware: "^0.5.1"

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:dynamic_middleware/dynamic_middleware.dart';
Version Uploaded Documentation Archive
0.5.1 Apr 12, 2018 Go to the documentation of dynamic_middleware 0.5.1 Download dynamic_middleware 0.5.1 archive
0.5.0 Apr 12, 2018 Go to the documentation of dynamic_middleware 0.5.0 Download dynamic_middleware 0.5.0 archive
0.4.0 Feb 11, 2018 Go to the documentation of dynamic_middleware 0.4.0 Download dynamic_middleware 0.4.0 archive
0.3.0 Feb 10, 2018 Go to the documentation of dynamic_middleware 0.3.0 Download dynamic_middleware 0.3.0 archive
0.2.0 Feb 10, 2018 Go to the documentation of dynamic_middleware 0.2.0 Download dynamic_middleware 0.2.0 archive


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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
100 / 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, web, other

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


  • 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.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.0
redux >=2.0.0 <3.0.0 2.1.1 3.0.0
Dev dependencies
test ^0.12.30