lesson_bloc.dart
1.16 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
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wow_english/common/request/dao/home_dao.dart';
import 'package:wow_english/common/request/exception.dart';
import 'package:wow_english/utils/loading.dart';
part 'lesson_event.dart';
part 'lesson_state.dart';
class LessonBloc extends Bloc<LessonEvent, LessonState> {
final int pageIndex;
final PageController pageController;
int _currentPageIndex = 0;
int get currentPageIndex => _currentPageIndex;
LessonBloc(this.pageIndex,this.pageController) : super(LessonInitial()) {
_currentPageIndex = pageIndex;
on<PageViewChangeIndexEvent>(_pageIndexChange);
}
Future<void> requestData() async {
try {
await loading(() async {
HomeDao.courseModule();
emit(LessonDataLoadState());
});
} catch (e) {
if (e is ApiException) {
}
}
}
void _pageIndexChange(PageViewChangeIndexEvent event,Emitter<LessonState> emitter) async {
_currentPageIndex = event.index;
emitter(PageIndexChangeState());
}
@override
Future<void> close() {
pageController.dispose();
return super.close();
}
}