首页 > 解决方案 > Flutter Redux Middleware

问题描述

I'm completely new to redux and it's beginning to make sense. I'm trying to use the middleware to keep the reducer a pure function but it's giving me an error I don't understand. I'm following the flutter architecture samples for redux

void main() {
  final store = Store<AppState>(
    appReducer,
    initialState: AppState.loading(),
    middleware: createStoreFlashCardsMiddleware(),
  );
  runApp(new MyApp(store));
}

//the middleware

List<Middleware<AppState>> createStoreFlashCardsMiddleware() {
  final loadFlashCards = _createLoadFlashCardsMiddleware();
  final saveFlashCards = _createSaveFlashCardsMiddleWare();

  return [
    TypedMiddleware<AppState, FetchFlashCardsAction>(loadFlashCards),
    TypedMiddleware<AppState, AddFlashCardAction>(saveFlashCards),
    TypedMiddleware<AppState, ClearCompletedAction>(saveFlashCards),
    TypedMiddleware<AppState, ToggleAllAction>(saveFlashCards),
    TypedMiddleware<AppState, UpdateFlashCardAction>(saveFlashCards),
    TypedMiddleware<AppState, FetchCardsSucceededAction>(saveFlashCards),
    TypedMiddleware<AppState, DeleteFlashCardAction>(saveFlashCards),
  ];
}

Middleware<AppState> _createSaveFlashCardsMiddleWare() {
  return (Store store, action, NextDispatcher next) async {
  // YOUR LOGIC HERE
  // After you do whatever logic you need to do,
  // call this Redux built-in method,
  // It continues the redux cycle.
  next(action);
  };
}

Middleware<AppState> _createLoadFlashCardsMiddleware() {
  return (Store store, action, NextDispatcher next) async {
  next(action);
  };
}

The error is:

error: The argument type 'List<(Store<AppState>, dynamic, (dynamic) → void) → void> (C:\flutter\bin\cache\pkg\sky_engine\lib\core\list.dart)' can't be assigned to
the parameter type 'List<(Store<AppState>, dynamic, (dynamic) → void) → void> (C:\flutter\bin\cache\pkg\sky_engine\lib\core\list.dart)'. (argument_type_not_assignable at [line])

标签: reduxdartflutter

解决方案


推荐阅读