Flutter typedMiddleware

387 Views Asked by At

I am kinda new to flutter and trying out the flutter redux library but I am stuck with having a proper list of middlewares.

import 'package:flutter_app/incrementButtonScreen/IncrementButtonActions.dart';
import 'package:flutter_app/incrementButtonScreen/IncrementButtonLogicStates.dart';
import 'package:flutter_app/incrementButtonScreen/IncrementButtonState.dart';
import 'package:redux/redux.dart';

List<Middleware<IncrementButtonState>> createIncrementButtonStoreMiddleware = [
  TypedMiddleware<IncrementButtonState, Increment>(createIncrement("typed")),
  createIncrement("normal")
];

Middleware<IncrementButtonState> createIncrement(String logger) {
  return (Store store, action, NextDispatcher next) {
    print('\n ACTION $logger : ${new DateTime.now()}: $action');
    // some api call happening here and passing the APi call result next
    next(IncrementButtonLogicIncrementState(220, 15.0));
  };
}

the issue is, I only get the logs from the normal middleWare but never from typed version. I am trying to rework the counter example and dispatching action class Increment{} on fab click store.dispatch(Increment); I am creating my store here:

Store createIncrementButtonStore() {
  return new Store<IncrementButtonState>(_counterReducer,
      initialState: IncrementButtonState.initial(), middleware: createIncrementButtonStoreMiddleware);
}

when I replace TypedMiddleware<IncrementButtonState, Increment> with TypedMiddleware<IncrementButtonState, dynamic> then I get the it works

ACTION typed : 2018-08-06 12:04:45.778293: Increment
     ACTION normal : 2018-08-06 12:04:45.778411: Instance of 'IncrementButtonLogicIncrementState'
1

There are 1 best solutions below

0
On

After a long time of searching, I found that I was dispatching Increment which is eqivalent to Increment.class in java I believe, after dispatching Increment() it works fine