bloc.dart
1.41 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import 'package:bloc/bloc.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:wow_english/models/app_config_entity.dart';
import '../../common/core/app_config_helper.dart';
import 'event.dart';
import 'state.dart';
class ModuleSelectBloc extends Bloc<ModuleSelectEvent, ModuleSelectState> {
ModuleSelectBloc() : super(ModuleSelectState().init()) {
on<InitEvent>(_init);
}
void _init(InitEvent event, Emitter<ModuleSelectState> emit) async {
await _checkUpdate(emit);
debugPrint('WQF ModuleSelectBloc _init');
}
Future<void> _checkUpdate(Emitter<ModuleSelectState> emit) async {
int localVersion = int.parse(await AppConfigHelper.getAppVersion());
AppConfigEntity? appConfigEntity = await AppConfigHelper.getAppConfig();
if (appConfigEntity == null) {
return;
}
debugPrint('WQF _checkUpdate');
if (defaultTargetPlatform == TargetPlatform.iOS) {
if (localVersion < appConfigEntity.iosVersion &&
appConfigEntity.iosRecommendUpdate == true) {
emit(UpdateDialogState(
appConfigEntity.iosForceUpdate ?? false, appConfigEntity));
}
} else {
if (localVersion < appConfigEntity.androidVersion &&
appConfigEntity.androidRecommendUpdate == true) {
emit(UpdateDialogState(
appConfigEntity.androidForceUpdate ?? false, appConfigEntity,
));
}
}
}
}