| 123456789101112131415161718192021222324252627282930 |
- import '../model/UserInfo.dart';
- enum Actions { updateToken, updateUser, updateAll, logout }
- class AppState {
- bool isLogin = false;
- UserInfo userInfo;
- AppState(this.isLogin, this.userInfo);
- AppState.empty();
- }
- AppState appReducer(AppState state, action) {
- print(action);
- if (Actions.updateAll == action['action']) {
- state.userInfo = UserInfo.fromJson(action['user']);
- state.isLogin = true;
- return state;
- } else if (Actions.updateUser == action['action']) {
- state.userInfo = UserInfo.fromJson(action['user']);
- return state;
- } else if (Actions.logout == action['action']) {
- state.userInfo = null;
- state.isLogin = false;
- return state;
- } else {
- return AppState.empty();
- }
- }
|