AppState.dart 731 B

123456789101112131415161718192021222324252627282930
  1. import '../model/UserInfo.dart';
  2. enum Actions { updateToken, updateUser, updateAll, logout }
  3. class AppState {
  4. bool isLogin = false;
  5. UserInfo userInfo;
  6. AppState(this.isLogin, this.userInfo);
  7. AppState.empty();
  8. }
  9. AppState appReducer(AppState state, action) {
  10. print(action);
  11. if (Actions.updateAll == action['action']) {
  12. state.userInfo = UserInfo.fromJson(action['user']);
  13. state.isLogin = true;
  14. return state;
  15. } else if (Actions.updateUser == action['action']) {
  16. state.userInfo = UserInfo.fromJson(action['user']);
  17. return state;
  18. } else if (Actions.logout == action['action']) {
  19. state.userInfo = null;
  20. state.isLogin = false;
  21. return state;
  22. } else {
  23. return AppState.empty();
  24. }
  25. }