Flutter Redux和Flatter:管理商店

Flutter Redux和Flatter:管理商店,flutter,redux,redux-thunk,Flutter,Redux,Redux Thunk,我正在创建我的第一个颤振应用程序,并尝试使用Redux 我有这个商店,我设法从2个不同的教程创建 这是一个获取帖子的示例,99%的代码都是从中复制的 代码的其余部分与之前完全相同,我只添加了关于注册商店的行 为什么它需要类型为“SetSignUpStateAction”的值 谢谢你的帮助 AppState appReducer(AppState state, action) { return AppState( postsState: postsReducer(state.p

我正在创建我的第一个颤振应用程序,并尝试使用Redux

我有这个商店,我设法从2个不同的教程创建

这是一个获取帖子的示例,99%的代码都是从中复制的

代码的其余部分与之前完全相同,我只添加了关于注册商店的行

为什么它需要类型为“SetSignUpStateAction”的值

谢谢你的帮助

AppState appReducer(AppState state, action) {
  return AppState(    
    postsState: postsReducer(state.postsState, action),
  );
}

@immutable
class AppState {
  final PostsState postsState;
  AppState({
    @required this.postsState,
  });

  AppState copyWith({
    PostsState postsState,
  }) {
    return AppState(
      postsState: postsState ?? this.postsState,
    );
  }
}

class Redux {
  static Store<AppState> _store;

  static Store<AppState> get store {
    if (_store == null) {
      throw Exception("store is not initialized");
    } else {
      return _store;
    }
  }

  static Future<void> init() async {
    final postsStateInitial = PostsState.initial();
    _store = Store<AppState>(
      appReducer,
      middleware: [thunkMiddleware, new LoggingMiddleware.printer()],
      initialState: AppState(
          postsState: postsStateInitial,
      ),
    );
  }
}
AppState appReducer(AppState state, action) {
  return AppState(
    signUpState: signUpReducer(state.signUpState, action),
    postsState: postsReducer(state.postsState, action),
  );
}

@immutable
class AppState {
  final PostsState postsState;
  final SignUpState signUpState;

  AppState({
    @required this.postsState,
    @required this.signUpState,
  });

  AppState copyWith({
    PostsState postsState,
    SignUpState signUpState,
  }) {
    return AppState(
      postsState: postsState ?? this.postsState,
      signUpState: signUpState ?? this.signUpState,
    );
  }
}

class Redux {
  static Store<AppState> _store;

  static Store<AppState> get store {
    if (_store == null) {
      throw Exception("store is not initialized");
    } else {
      return _store;
    }
  }

  static Future<void> init() async {
    final postsStateInitial = PostsState.initial();
    final signUpStateInitial = SignUpState.initial();

    _store = Store<AppState>(
      appReducer,
      middleware: [thunkMiddleware, new LoggingMiddleware.printer()],
      initialState: AppState(
          postsState: postsStateInitial,
          signUpState: signUpStateInitial,
      ),
    );
  }
}
errors.dart:167 Uncaught (in promise) Error: Expected a value of type 'SetSignUpStateAction', but got one of type 'SetPostsStateAction'