d35a4e87
liangchengyou
feat:磨耳朵功能UI
|
1
|
import 'package:flutter/cupertino.dart';
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
2
|
import 'package:flutter/foundation.dart';
|
d35a4e87
liangchengyou
feat:磨耳朵功能UI
|
3
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2187c85f
吴启风
feat:课程结构调整
|
4
|
import 'package:wow_english/common/request/dao/lesson_dao.dart';
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
5
|
import 'package:wow_english/common/request/exception.dart';
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
6
7
|
import 'package:wow_english/common/request/dao/listen_dao.dart';
import 'package:wow_english/models/course_process_entity.dart';
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
8
|
import 'package:wow_english/utils/loading.dart';
|
c61b3c1a
Key
feat: toast_util....
|
9
|
import 'package:wow_english/utils/toast_util.dart';
|
60e47f7c
liangchengyou
feat:课程选择功能
|
10
|
|
2187c85f
吴启风
feat:课程结构调整
|
11
12
|
import '../../../models/course_section_entity.dart';
import '../../../models/course_unit_entity.dart';
|
3ba925a9
吴启风
feat:环节页增加翻页切换单元效果
|
13
|
import '../../../utils/list_ext.dart';
|
60e47f7c
liangchengyou
feat:课程选择功能
|
14
|
|
2187c85f
吴启风
feat:课程结构调整
|
15
16
|
part 'section_event.dart';
part 'section_state.dart';
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
17
|
|
2187c85f
吴启风
feat:课程结构调整
|
18
|
class SectionBloc extends Bloc<SectionEvent, SectionState> {
|
c61b3c1a
Key
feat: toast_util....
|
19
|
|
3ba925a9
吴启风
feat:环节页增加翻页切换单元效果
|
20
21
22
23
24
25
26
27
28
29
30
31
32
|
PageController _pageController;
PageController get pageController => _pageController;
///当前页索引
int _currentPage = 0;
int get currentPage => _currentPage;
ScrollController _listController;
ScrollController get listController => _listController;
|
2187c85f
吴启风
feat:课程结构调整
|
33
34
35
36
37
38
39
40
41
42
43
|
CourseUnitEntity _courseUnitEntity;
CourseUnitEntity get courseUnitEntity => _courseUnitEntity;
CourseUnitDetail _courseUnitDetail;
CourseUnitDetail get courseUnitDetail => _courseUnitDetail;
List<CourseSectionEntity>? _courseSectionDatas;
List<CourseSectionEntity>? get courseSectionDatas => _courseSectionDatas;
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
44
|
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
45
46
47
48
|
CourseProcessEntity? _processEntity;
CourseProcessEntity? get processEntity => _processEntity;
|
3ba925a9
吴启风
feat:环节页增加翻页切换单元效果
|
49
|
SectionBloc(this._courseUnitEntity, this._courseUnitDetail, this._pageController, this._listController) : super(LessonInitial()) {
|
993c1a04
liangchengyou
feat:添加数据模型
|
50
|
on<RequestDataEvent>(_requestData);
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
51
52
|
on<RequestExitClassEvent>(_requestExitClass);
on<RequestEnterClassEvent>(_requestEnterClass);
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
53
|
on<RequestVideoLessonEvent>(_requestVideoLesson);
|
3ba925a9
吴启风
feat:环节页增加翻页切换单元效果
|
54
|
on<CurrentUnitIndexChangeEvent>(_pageControllerChange);
|
60e47f7c
liangchengyou
feat:课程选择功能
|
55
|
}
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
56
|
|
2187c85f
吴启风
feat:课程结构调整
|
57
|
void _requestData(RequestDataEvent event, Emitter<SectionState> emitter) async {
|
993c1a04
liangchengyou
feat:添加数据模型
|
58
59
|
try {
await loading(() async {
|
2187c85f
吴启风
feat:课程结构调整
|
60
61
|
_courseSectionDatas = await LessonDao.courseSection(courseUnitId: _courseUnitDetail.id!);
emitter(LessonDataLoadState());
|
993c1a04
liangchengyou
feat:添加数据模型
|
62
63
64
|
});
} catch (e) {
if (e is ApiException) {
|
c61b3c1a
Key
feat: toast_util....
|
65
|
showToast(e.message.toString());
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
66
67
68
|
}
}
}
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
69
|
|
2187c85f
吴启风
feat:课程结构调整
|
70
|
void _requestVideoLesson(RequestVideoLessonEvent event, Emitter<SectionState> emitter) async {
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
71
72
73
|
try {
await loading(() async {
_processEntity = await ListenDao.process(event.courseLessonId);
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
74
|
emitter(RequestVideoLessonState(event.courseLessonId,event.courseType));
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
75
76
77
78
79
80
81
|
});
} catch (e) {
if (e is ApiException) {
showToast(e.message??'请求失败,请检查网络连接');
}
}
}
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
82
83
|
|
2187c85f
吴启风
feat:课程结构调整
|
84
|
void _requestEnterClass(RequestEnterClassEvent event,Emitter<SectionState> emitter) async {
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
85
86
87
88
89
90
91
92
93
94
95
96
|
try {
await loading(() async {
await ListenDao.enterClass(event.courseLessonId);
emitter(RequestEnterClassState(event.courseLessonId,event.courseType));
});
} catch (e) {
if (e is ApiException) {
showToast(e.message??'请求失败,请检查网络连接');
}
}
}
|
2187c85f
吴启风
feat:课程结构调整
|
97
|
void _requestExitClass(RequestExitClassEvent event,Emitter<SectionState> emitter) async {
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
98
99
|
await ListenDao.exitClass(event.courseLessonId,event.currentStep,event.currentTime);
}
|
3ba925a9
吴启风
feat:环节页增加翻页切换单元效果
|
100
101
102
103
104
105
106
107
108
109
110
|
void _pageControllerChange(CurrentUnitIndexChangeEvent event,
Emitter<SectionState> emitter) async {
_currentPage = event.unitIndex;
emitter(CurrentPageIndexState());
}
// 未锁定的页数
int unlockPageCount() {
return _courseUnitEntity.courseUnitVOList?.indexWhereOrNull((element) => element.lock == true) ?? 1;
}
|
60e47f7c
liangchengyou
feat:课程选择功能
|
111
|
}
|