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';
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
4
5
|
import 'package:wow_english/common/request/dao/home_dao.dart';
import 'package:wow_english/common/request/exception.dart';
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
6
|
import 'package:wow_english/models/course_entity.dart';
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
7
8
|
import 'package:wow_english/common/request/dao/listen_dao.dart';
import 'package:wow_english/models/course_process_entity.dart';
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
9
|
import 'package:wow_english/utils/loading.dart';
|
c61b3c1a
Key
feat: toast_util....
|
10
|
import 'package:wow_english/utils/toast_util.dart';
|
60e47f7c
liangchengyou
feat:课程选择功能
|
11
12
13
14
15
|
part 'home_event.dart';
part 'home_state.dart';
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
16
17
18
|
final String? moduleId;
CourseEntity? _modelData;
|
c61b3c1a
Key
feat: toast_util....
|
19
|
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
20
21
|
CourseEntity? get modelData => _modelData;
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
22
23
24
25
|
CourseProcessEntity? _processEntity;
CourseProcessEntity? get processEntity => _processEntity;
|
8988aa69
liangchengyou
feat:首页+课程列表数据获取
|
26
|
HomeBloc(this.moduleId) : super(HomeInitial()) {
|
993c1a04
liangchengyou
feat:添加数据模型
|
27
|
on<RequestDataEvent>(_requestData);
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
28
29
|
on<RequestExitClassEvent>(_requestExitClass);
on<RequestEnterClassEvent>(_requestEnterClass);
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
30
|
on<RequestVideoLessonEvent>(_requestVideoLesson);
|
60e47f7c
liangchengyou
feat:课程选择功能
|
31
|
}
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
32
|
|
993c1a04
liangchengyou
feat:添加数据模型
|
33
34
35
|
void _requestData(RequestDataEvent event, Emitter<HomeState> emitter) async {
try {
await loading(() async {
|
c61b3c1a
Key
feat: toast_util....
|
36
|
_modelData = await HomeDao.courseLesson(moduleId: moduleId ?? '');
|
993c1a04
liangchengyou
feat:添加数据模型
|
37
38
39
40
|
emitter(HomeDataLoadState());
});
} catch (e) {
if (e is ApiException) {
|
c61b3c1a
Key
feat: toast_util....
|
41
|
showToast(e.message.toString());
|
13e6d11d
liangchengyou
feat:首页课程模块接口
|
42
43
44
|
}
}
}
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
45
46
47
48
49
|
void _requestVideoLesson(RequestVideoLessonEvent event, Emitter<HomeState> emitter) async {
try {
await loading(() async {
_processEntity = await ListenDao.process(event.courseLessonId);
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
50
|
emitter(RequestVideoLessonState(event.courseLessonId,event.courseType));
|
3c1d5c64
liangchengyou
feat:练习功能完成
|
51
52
53
54
55
56
57
|
});
} catch (e) {
if (e is ApiException) {
showToast(e.message??'请求失败,请检查网络连接');
}
}
}
|
934e2b47
liangchengyou
feat:权限调整+课程进度接口对接
|
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
void _requestEnterClass(RequestEnterClassEvent event,Emitter<HomeState> emitter) async {
try {
await loading(() async {
await ListenDao.enterClass(event.courseLessonId);
emitter(RequestEnterClassState(event.courseLessonId,event.courseType));
});
} catch (e) {
if (e is ApiException) {
showToast(e.message??'请求失败,请检查网络连接');
}
}
}
void _requestExitClass(RequestExitClassEvent event,Emitter<HomeState> emitter) async {
await ListenDao.exitClass(event.courseLessonId,event.currentStep,event.currentTime);
}
|
60e47f7c
liangchengyou
feat:课程选择功能
|
76
|
}
|