look_video_bloc.dart
1.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:video_player/video_player.dart';
import 'package:wow_english/pages/section/subsection/base_section/bloc.dart';
import 'package:wow_english/pages/section/subsection/base_section/event.dart';
import 'package:wow_english/pages/section/subsection/base_section/state.dart';
import '../../../../common/request/dao/listen_dao.dart';
import '../../../../common/request/exception.dart';
import '../../../../models/course_process_entity.dart';
import '../../../../utils/loading.dart';
import '../../../../utils/toast_util.dart';
part 'look_video_event.dart';
part 'look_video_state.dart';
class LookVideoBloc extends BaseSectionBloc<BaseSectionEvent, BaseSectionState> {
final String? _videoUrl;
String? get videoUrl => (_videoUrl?.isNotEmpty == true) ? _videoUrl : _entity?.videos?.videoUrl ?? '';
final String? _typeTitle;
String? get typeTitle => _typeTitle;
final String? _courseLessonId;
String? get courseLessonId => _courseLessonId;
final bool _isTopic;
bool get isTopic => _isTopic;
CourseProcessEntity? _entity;
CourseProcessEntity? get entity => _entity;
LookVideoBloc(this._videoUrl, this._typeTitle, this._courseLessonId, this._isTopic) : super(LookVideoInitial()) {
on<LookVideoEvent>((event, emit) {
// TODO: implement event handler
});
on<RequestDataEvent>(_requestData);
on<SectionAgainEvent>((event, emit) {
emit(SectionAgainState());
});
}
///请求数据
void _requestData(
RequestDataEvent event, Emitter<BaseSectionState> emitter) async {
try {
await loading(() async {
_entity = await ListenDao.process(courseLessonId);
emitter(RequestDataState());
});
} catch (e) {
if (e is ApiException) {
showToast(e.message ?? '请求失败,请检查网络连接');
}
}
}
}