Blame view

lib/common/blocs/cachebloc/cache_bloc.dart 728 Bytes
fcc3a982   liangchengyou   feat:全局缓存bloc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  import 'package:flutter/cupertino.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:wow_english/models/user_entity.dart';
  
  part 'cache_event.dart';
  part 'cache_state.dart';
  
  class CacheBloc extends Bloc<CacheEvent, CacheState> {
    UserEntity? _userEntity;
  
    UserEntity? get userEntity => _userEntity;
  
    CacheBloc() : super(CacheInitial()) {
      on<UserInfoChangeEvent>(_userInfoChange);
    }
  
    void _userInfoChange(UserInfoChangeEvent event,Emitter<CacheState> emitter) async {
      _userEntity = event.userEntity;
      emitter(UserInfoChangeState());
    }
  
    void _userInfoClear(UserInfoClearEvent event,Emitter<CacheState> emitter) async {
      _userEntity = null;
      emitter(UserInfoClearState());
    }
  }