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 { 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((event, emit) { // TODO: implement event handler }); on(_requestData); on((event, emit) { emit(SectionAgainState()); }); } ///请求数据 void _requestData( RequestDataEvent event, Emitter emitter) async { try { await loading(() async { _entity = await ListenDao.process(courseLessonId); emitter(RequestDataState()); }); } catch (e) { if (e is ApiException) { showToast(e.message ?? '请求失败,请检查网络连接'); } } } }