Flutter Redux中间件

时间:2018-06-13 21:44:24

标签: redux dart flutter

很抱歉,如果答案很明显,但我傻眼了。我对redux来说是全新的,它开始变得有意义了。我试图使用中间件来使减速器保持纯粹的功能,但它给了我一个我不明白的错误。我正在关注redux的颤振架构样本

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

//中间件

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

错误是:

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

0 个答案:

没有答案