Blame view

lib/pages/unit/bloc.dart 1.73 KB
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
1
  import 'package:bloc/bloc.dart';
2187c85f   吴启风   feat:课程结构调整
2
  import 'package:wow_english/pages/unit/widget/home_tab_header_widget.dart';
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
3
  
2187c85f   吴启风   feat:课程结构调整
4
  import '../../common/request/dao/lesson_dao.dart';
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
5
  import '../../common/request/exception.dart';
2187c85f   吴启风   feat:课程结构调整
6
  import '../../models/course_module_entity.dart';
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
7
  import '../../models/course_unit_entity.dart';
2187c85f   吴启风   feat:课程结构调整
8
  import '../../route/route.dart';
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
9
10
11
12
13
14
15
  import '../../utils/loading.dart';
  import '../../utils/toast_util.dart';
  import 'event.dart';
  import 'state.dart';
  
  class UnitBloc extends Bloc<UnitEvent, UnitState> {
  
2187c85f   吴启风   feat:课程结构调整
16
    CourseModuleEntity? _moduleEntity;
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
17
  
2187c85f   吴启风   feat:课程结构调整
18
    CourseModuleEntity? get moduleEntity => _moduleEntity;
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
19
  
2187c85f   吴启风   feat:课程结构调整
20
    CourseUnitEntity? _unitData;
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
21
  
2187c85f   吴启风   feat:课程结构调整
22
23
24
25
    CourseUnitEntity? get unitData => _unitData;
  
  
    UnitBloc(CourseModuleEntity? courseEntity) : super(UnitState().init()) {
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
26
27
28
29
30
31
      on<RequestUnitDataEvent>(_requestData);
    }
  
    void _requestData(RequestUnitDataEvent event, Emitter<UnitState> emitter) async {
      try {
        await loading(() async {
2187c85f   吴启风   feat:课程结构调整
32
          _unitData = await LessonDao.courseUnit(event.moduleId);
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
33
34
35
36
37
38
39
40
          emitter(UnitDataLoadState());
        });
      } catch (e) {
        if (e is ApiException) {
          showToast(e.message ?? '请求失败,请检查网络连接');
        }
      }
    }
2187c85f   吴启风   feat:课程结构调整
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  
    String? getCourseModuleCode() {
      return _moduleEntity?.code ?? _unitData?.courseModuleCode;
    }
  
    void headerActionEvent(HeaderActionType type) {
      if (type == HeaderActionType.video) {
        pushNamed(AppRouteName.reAfter);
      } else if (type == HeaderActionType.phase) {
        pushNamed(AppRouteName.courseModule);
      } else if (type == HeaderActionType.listen) {
        pushNamed(AppRouteName.listen);
      } else if (type == HeaderActionType.shop) {
        pushNamed(AppRouteName.shop);
      } else if (type == HeaderActionType.user) {
        pushNamed(AppRouteName.user);
      }
    }
2a3621f8   吴启风   feat:课程层级调整(增加unit层)
59
  }