dynamic_middleware 0.4.0

  • README.md
  • Example
  • Installing
  • Versions
  • new49

Dynamic Middleware for Redux

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>();
store = new Store<State>(reducer, middleware: [

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

Then add and remove middleware as you need.

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

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





  • 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, dynamic 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, dynamic action, NextDispatcher next) => stdout.writeln("Middleware enabled");

void main() {
  dynamicMiddleware = new DynamicMiddleware<int>();
  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: ")


1. Depend on it

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

  dynamic_middleware: "^0.4.0"

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


This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 11, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1


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


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
Dev dependencies
test ^0.12.30