section_page.dart
10.9 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:nested_scroll_views/material.dart';
import 'package:wow_english/common/core/user_util.dart';
import 'package:wow_english/common/extension/string_extension.dart';
import 'package:wow_english/models/course_unit_entity.dart';
import 'package:wow_english/pages/section/section_type.dart';
import 'package:wow_english/pages/section/widgets/section_item.dart';
import 'package:wow_english/pages/section/widgets/section_bouns_item.dart';
import 'package:wow_english/pages/section/widgets/section_header_widget.dart';
import 'package:wow_english/route/route.dart';
import 'package:wow_english/utils/toast_util.dart';
import '../../models/course_section_entity.dart';
import 'bloc/section_bloc.dart';
import 'courese_module_model.dart';
/// 环节列表页
class SectionPage extends StatelessWidget {
const SectionPage(
{super.key, required this.courseUnitEntity, required this.courseUnitId});
final CourseUnitEntity courseUnitEntity;
/// unitId
final int courseUnitId;
@override
Widget build(BuildContext context) {
int initialPage = courseUnitEntity.courseUnitVOList
?.indexWhere((element) => element.id == courseUnitId) ??
0;
return BlocProvider(
create: (context) => SectionBloc(courseUnitEntity, initialPage,
PageController(initialPage: initialPage), ScrollController()),
child: _SectionPageView(context),
);
}
}
class _SectionPageView extends StatelessWidget {
const _SectionPageView(this.context);
final BuildContext context;
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<SectionBloc>(context);
return BlocListener<SectionBloc, SectionState>(
listener: (context, state) {
if (state is RequestVideoLessonState) {
final videoUrl = bloc.processEntity?.videos?.videoUrl ?? '';
var title = '';
if (state.type == SectionType.song.value) {
title = 'song';
}
if (state.type == SectionType.video.value) {
title = 'video';
}
if (state.type == SectionType.bouns.value) {
title = 'bonus';
}
if (videoUrl.isEmpty || !videoUrl.contains('http')) {
return;
}
pushNamed(AppRouteName.lookVideo, arguments: {
'videoUrl': videoUrl,
'title': title,
'courseLessonId': state.courseLessonId,
'isTopic': true
}).then((value) {
if (value != null) {
Map<String, dynamic> dataMap = value as Map<String, dynamic>;
bloc.add(RequestEndClassEvent(
dataMap['courseLessonId']!, dataMap['isCompleted'],
currentTime: dataMap['currentTime'],
autoNextSection: dataMap['nextSection']));
}
});
return;
}
if (state is RequestEnterClassState) {
if (state.courseType != SectionType.practice.value &&
state.courseType != SectionType.pictureBook.value) {
///视频类型
///获取视频课程内容
bloc.add(RequestVideoLessonEvent(
state.courseLessonId, state.courseType));
return;
}
if (state.courseType == SectionType.pictureBook.value) {
//绘本
pushNamed(AppRouteName.reading,
arguments: {'courseLessonId': state.courseLessonId})
.then((value) {
if (value != null) {
Map<String, dynamic> dataMap = value as Map<String, dynamic>;
bloc.add(RequestEndClassEvent(
dataMap['courseLessonId']!,
dataMap['isCompleted'],
currentStep: dataMap['currentStep'],
autoNextSection: dataMap['nextSection'],
));
}
});
return;
}
if (state.courseType == SectionType.practice.value) {
//练习
pushNamed(AppRouteName.topicPic,
arguments: {'courseLessonId': state.courseLessonId})
.then((value) {
if (value != null) {
Map<String, dynamic> dataMap = value as Map<String, dynamic>;
bloc.add(RequestEndClassEvent(
dataMap['courseLessonId']!, dataMap['isCompleted'],
currentStep: dataMap['currentStep'],
autoNextSection: dataMap['nextSection']));
}
});
return;
}
}
},
child: _sectionView(),
);
}
Widget _sectionView() =>
BlocBuilder<SectionBloc, SectionState>(builder: (context, state) {
final bloc = BlocProvider.of<SectionBloc>(context);
return Scaffold(
body: Container(
color: Colors.white,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SectionHeaderWidget(
title: bloc.getCourseUnitDetail().name,
courseModuleCode: bloc.courseUnitEntity.courseModuleCode),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10.w),
child: OverflowBox(
child: NestedPageView.builder(
itemCount: bloc.unlockPageCount(),
controller: bloc.pageController,
onPageChanged: (int index) {
bloc.add(CurrentUnitIndexChangeEvent(index));
},
itemBuilder: (context, index) {
return ScrollConfiguration(
///去掉 Android 上默认的边缘拖拽效果
behavior: ScrollConfiguration.of(context)
.copyWith(overscroll: false),
child: _itemTransCard(
bloc.getCourseUnitDetail(pageIndex: index),
index,
context),
);
}),
), // 设置外部padding,
)),
SafeArea(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 13.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 47.h,
width: 80.w,
),
Container(
decoration: BoxDecoration(
color: CourseModuleModel(
bloc.courseUnitEntity.courseModuleCode ??
'Phase-1')
.color,
borderRadius: BorderRadius.circular(14.5.r),
),
padding: EdgeInsets.symmetric(
vertical: 8.h, horizontal: 24.w),
child: Text(
'${bloc.currentPage + 1}/${bloc.unlockPageCount()}',
style: TextStyle(
color: Colors.white, fontSize: 12.sp),
),
),
Image.asset(
CourseModuleModel(
bloc.courseUnitEntity.courseModuleCode ??
'Phase-1')
.courseModuleLogo
.assetPng,
height: 47.h,
width: 80.w,
// color: Colors.red,
),
],
),
),
)
],
),
),
),
);
});
}
Widget _itemTransCard(
CourseUnitDetail courseUnitDetail, int pageIndex, BuildContext context) {
final bloc = BlocProvider.of<SectionBloc>(context);
List<CourseSectionEntity>? courseSectionEntities =
bloc.courseSectionDatasMap[courseUnitDetail.id];
if (courseSectionEntities == null) {
bloc.add(RequestDataEvent(courseUnitDetail.id!));
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'暂无数据',
style: TextStyle(fontSize: 24.0),
),
const SizedBox(height: 16.0),
// 间距
CircularProgressIndicator(
color: CourseModuleModel(
bloc.courseUnitEntity.courseModuleCode ?? 'Phase-1')
.color),
// 加载动画
],
),
);
} else {
return NestedListView.builder(
itemCount: bloc.courseSectionDatasMap[courseUnitDetail.id]?.length ?? 0,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
CourseSectionEntity sectionData = courseSectionEntities[index];
if (sectionData.courseType == SectionType.bouns.value) {
//彩蛋
return GestureDetector(
onTap: () {
if (!UserUtil.isLogined()) {
pushNamed(AppRouteName.login);
return;
}
if (sectionData.lock == true) {
showToast('当前课程暂未解锁');
return;
}
///进入课堂
bloc.add(RequestEnterClassEvent(
sectionData.id.toString(), sectionData.courseType));
},
child: SectionBoundsItem(
imageUrl: sectionData.coverUrl,
),
);
} else {
return GestureDetector(
onTap: () {
if (!UserUtil.isLogined()) {
pushNamed(AppRouteName.login);
return;
}
if (sectionData.lock == true) {
showToast('当前课程暂未解锁');
return;
}
///进入课堂
bloc.add(RequestEnterClassEvent(
sectionData.id.toString(), sectionData.courseType));
},
child: SectionItem(
courseModuleId: bloc.courseUnitEntity.courseModuleCode,
lessons: sectionData,
),
);
}
});
}
}