Commit 13e6d11d22b42f46e7ee9c325ff3a8aa958683f2
1 parent
bff5c18b
feat:首页课程模块接口
Showing
7 changed files
with
56 additions
and
7 deletions
lib/common/request/dao/home_dao.dart
0 → 100644
1 | +import 'package:wow_english/common/request/apis.dart'; | |
2 | +import 'package:wow_english/common/request/request_client.dart'; | |
3 | + | |
4 | +class HomeDao { | |
5 | + ///获取课程模块信息 | |
6 | + static Future courseModule() async { | |
7 | + var data = requestClient.get(Apis.courseModule); | |
8 | + return data; | |
9 | + } | |
10 | + | |
11 | + ///课程列表 | |
12 | + static Future courseLesson() async { | |
13 | + var data = requestClient.get(Apis.courseLesson); | |
14 | + return data; | |
15 | + } | |
16 | +} | ... | ... |
lib/pages/home/bloc/home_bloc.dart
1 | 1 | import 'package:flutter/cupertino.dart'; |
2 | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | +import 'package:wow_english/common/request/dao/home_dao.dart'; | |
4 | +import 'package:wow_english/common/request/exception.dart'; | |
5 | +import 'package:wow_english/utils/loading.dart'; | |
3 | 6 | |
4 | 7 | part 'home_event.dart'; |
5 | 8 | part 'home_state.dart'; |
6 | 9 | |
7 | 10 | class HomeBloc extends Bloc<HomeEvent, HomeState> { |
8 | - final PageController pageController; | |
9 | - HomeBloc(this.pageController) : super(HomeInitial()) { | |
11 | + HomeBloc() : super(HomeInitial()) { | |
10 | 12 | on<HomeEvent>((event, emit) { |
11 | 13 | // TODO: implement event handler |
12 | 14 | }); |
13 | 15 | } |
16 | + | |
17 | + Future<void> requestData() async { | |
18 | + try { | |
19 | + await loading(() async { | |
20 | + HomeDao.courseLesson(); | |
21 | + emit(HomeDataLoadState()); | |
22 | + }); | |
23 | + } catch (e) { | |
24 | + if (e is ApiException) { | |
25 | + | |
26 | + } | |
27 | + } | |
28 | + } | |
14 | 29 | } | ... | ... |
lib/pages/home/bloc/home_state.dart
lib/pages/home/home_page.dart
... | ... | @@ -14,9 +14,7 @@ class HomePage extends StatelessWidget { |
14 | 14 | @override |
15 | 15 | Widget build(BuildContext context) { |
16 | 16 | return BlocProvider( |
17 | - create: (context) => HomeBloc(PageController( | |
18 | - initialPage: 0, | |
19 | - )), | |
17 | + create: (context) => HomeBloc()..requestData(), | |
20 | 18 | child: _HomePageView(), |
21 | 19 | ); |
22 | 20 | } | ... | ... |
lib/pages/lessons/bloc/lesson_bloc.dart
1 | - | |
2 | 1 | import 'package:flutter/cupertino.dart'; |
3 | 2 | import 'package:flutter_bloc/flutter_bloc.dart'; |
3 | +import 'package:wow_english/common/request/dao/home_dao.dart'; | |
4 | +import 'package:wow_english/common/request/exception.dart'; | |
5 | +import 'package:wow_english/utils/loading.dart'; | |
4 | 6 | |
5 | 7 | part 'lesson_event.dart'; |
6 | 8 | part 'lesson_state.dart'; |
... | ... | @@ -20,6 +22,19 @@ class LessonBloc extends Bloc<LessonEvent, LessonState> { |
20 | 22 | on<PageViewChangeIndexEvent>(_pageIndexChange); |
21 | 23 | } |
22 | 24 | |
25 | + Future<void> requestData() async { | |
26 | + try { | |
27 | + await loading(() async { | |
28 | + HomeDao.courseModule(); | |
29 | + emit(LessonDataLoadState()); | |
30 | + }); | |
31 | + } catch (e) { | |
32 | + if (e is ApiException) { | |
33 | + | |
34 | + } | |
35 | + } | |
36 | + } | |
37 | + | |
23 | 38 | void _pageIndexChange(PageViewChangeIndexEvent event,Emitter<LessonState> emitter) async { |
24 | 39 | _currentPageIndex = event.index; |
25 | 40 | emitter(PageIndexChangeState()); | ... | ... |
lib/pages/lessons/bloc/lesson_state.dart
lib/pages/lessons/lesson_page.dart