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 | import 'package:flutter/cupertino.dart'; | 1 | import 'package:flutter/cupertino.dart'; |
2 | import 'package:flutter_bloc/flutter_bloc.dart'; | 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 | part 'home_event.dart'; | 7 | part 'home_event.dart'; |
5 | part 'home_state.dart'; | 8 | part 'home_state.dart'; |
6 | 9 | ||
7 | class HomeBloc extends Bloc<HomeEvent, HomeState> { | 10 | class HomeBloc extends Bloc<HomeEvent, HomeState> { |
8 | - final PageController pageController; | ||
9 | - HomeBloc(this.pageController) : super(HomeInitial()) { | 11 | + HomeBloc() : super(HomeInitial()) { |
10 | on<HomeEvent>((event, emit) { | 12 | on<HomeEvent>((event, emit) { |
11 | // TODO: implement event handler | 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,9 +14,7 @@ class HomePage extends StatelessWidget { | ||
14 | @override | 14 | @override |
15 | Widget build(BuildContext context) { | 15 | Widget build(BuildContext context) { |
16 | return BlocProvider( | 16 | return BlocProvider( |
17 | - create: (context) => HomeBloc(PageController( | ||
18 | - initialPage: 0, | ||
19 | - )), | 17 | + create: (context) => HomeBloc()..requestData(), |
20 | child: _HomePageView(), | 18 | child: _HomePageView(), |
21 | ); | 19 | ); |
22 | } | 20 | } |
lib/pages/lessons/bloc/lesson_bloc.dart
1 | - | ||
2 | import 'package:flutter/cupertino.dart'; | 1 | import 'package:flutter/cupertino.dart'; |
3 | import 'package:flutter_bloc/flutter_bloc.dart'; | 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 | part 'lesson_event.dart'; | 7 | part 'lesson_event.dart'; |
6 | part 'lesson_state.dart'; | 8 | part 'lesson_state.dart'; |
@@ -20,6 +22,19 @@ class LessonBloc extends Bloc<LessonEvent, LessonState> { | @@ -20,6 +22,19 @@ class LessonBloc extends Bloc<LessonEvent, LessonState> { | ||
20 | on<PageViewChangeIndexEvent>(_pageIndexChange); | 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 | void _pageIndexChange(PageViewChangeIndexEvent event,Emitter<LessonState> emitter) async { | 38 | void _pageIndexChange(PageViewChangeIndexEvent event,Emitter<LessonState> emitter) async { |
24 | _currentPageIndex = event.index; | 39 | _currentPageIndex = event.index; |
25 | emitter(PageIndexChangeState()); | 40 | emitter(PageIndexChangeState()); |
lib/pages/lessons/bloc/lesson_state.dart
@@ -6,3 +6,5 @@ abstract class LessonState {} | @@ -6,3 +6,5 @@ abstract class LessonState {} | ||
6 | class LessonInitial extends LessonState {} | 6 | class LessonInitial extends LessonState {} |
7 | 7 | ||
8 | class PageIndexChangeState extends LessonState {} | 8 | class PageIndexChangeState extends LessonState {} |
9 | + | ||
10 | +class LessonDataLoadState extends LessonState {} |
lib/pages/lessons/lesson_page.dart
@@ -21,7 +21,8 @@ class LessonPage extends StatelessWidget { | @@ -21,7 +21,8 @@ class LessonPage extends StatelessWidget { | ||
21 | PageController( | 21 | PageController( |
22 | initialPage: starPageIndex??0, | 22 | initialPage: starPageIndex??0, |
23 | viewportFraction: 0.3 | 23 | viewportFraction: 0.3 |
24 | - ),), | 24 | + ), |
25 | + )..requestData(), | ||
25 | child: _LessonPageView(), | 26 | child: _LessonPageView(), |
26 | ); | 27 | ); |
27 | } | 28 | } |