Blame view

lib/pages/home/bloc.dart 2 KB
82c8633c   biao   音频添加 页面优化
1
  import 'package:audioplayers/audioplayers.dart';
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
2
  import 'package:bloc/bloc.dart';
82c8633c   biao   音频添加 页面优化
3
  import 'package:wow_english/common/extension/string_extension.dart';
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
4
  
cde7505e   吴启风   feat:应用内升级
5
  import '../../common/core/app_config_helper.dart';
2c079546   吴启风   feat:应用内更新接口替换
6
7
8
  import '../../common/request/dao/system_dao.dart';
  import '../../models/app_version_entity.dart';
  import '../../utils/log_util.dart';
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
9
10
11
  import 'event.dart';
  import 'state.dart';
  
f74aeedc   吴启风   feat:首页类名调整
12
13
  class HomeBloc extends Bloc<HomeEvent, HomeState> {
    HomeBloc() : super(HomeState().init()) {
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
14
      on<InitEvent>(_init);
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
15
      on<ExchangeSuccessEvent>(_exchangeSuccess);
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
16
17
    }
  
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
18
    bool exchangeResult = false;
5e2bbbd3   biao   添加音频
19
20
21
22
23
24
25
26
27
28
29
30
31
    late AudioPlayer audioPlayer;
    late AudioPlayer studyPlayer;
    late AudioPlayer gamePlayer;
    @override
    Future<void> close() {
      audioPlayer.release();
      audioPlayer.dispose();
      studyPlayer.release();
      studyPlayer.dispose();
      gamePlayer.release();
      gamePlayer.dispose();
      return super.close();
    }
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
32
  
2187c85f   吴启风   feat:课程结构调整
33
    void _init(InitEvent event, Emitter<HomeState> emit) async {
5e2bbbd3   biao   添加音频
34
35
36
37
      audioPlayer = AudioPlayer(playerId: 'audio');
      gamePlayer = AudioPlayer(playerId: 'game');
      studyPlayer = AudioPlayer(playerId: 'study');
      audioPlayer.play(AssetSource('welcome_to_wow'.assetMp3));
cde7505e   吴启风   feat:应用内升级
38
      await _checkUpdate(emit);
cde7505e   吴启风   feat:应用内升级
39
40
    }
  
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
41
42
43
44
45
46
47
    void _exchangeSuccess(
        ExchangeSuccessEvent event, Emitter<HomeState> emit) async {
      if (exchangeResult) {
        emit(HomeState());
      }
    }
  
2187c85f   吴启风   feat:课程结构调整
48
    Future<void> _checkUpdate(Emitter<HomeState> emit) async {
2c079546   吴启风   feat:应用内更新接口替换
49
50
51
      if (AppConfigHelper.checkedUpdate) {
        return;
      }
cde7505e   吴启风   feat:应用内升级
52
      int localVersion = int.parse(await AppConfigHelper.getAppVersion());
2c079546   吴启风   feat:应用内更新接口替换
53
54
55
      AppVersionEntity? appVersionEntity = await SystemDao.getVersionInfo();
      AppConfigHelper.checkedUpdate = true;
      if (appVersionEntity == null) {
cde7505e   吴启风   feat:应用内升级
56
57
        return;
      }
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
58
59
      Log.d(
          "WQF _checkUpdate appVersionEntity: $appVersionEntity localVersion=$localVersion");
911794fd   吴启风   feat:审核控制增加ios平台条件判断
60
61
      if (localVersion < int.parse(appVersionEntity.version ?? '0')) {
        emit(UpdateDialogState(
e6a08b82   biao   修复兑换之后回到首页不刷新问题;修...
62
63
            appVersionEntity.volType == UpdateStrategy.FORCE.name,
            appVersionEntity));
cde7505e   吴启风   feat:应用内升级
64
      }
6d61919a   吴启风   feat:增加过渡页&集成串联游戏
65
66
    }
  }