Blame view

lib/pages/practice/topic_picture_page.dart 17.3 KB
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
1
2
3
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:flutter_screenutil/flutter_screenutil.dart';
2eb67dd4   liangchengyou   feat:调整代码
4
  import 'package:wow_english/common/blocs/cachebloc/cache_bloc.dart';
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
5
6
  import 'package:wow_english/common/extension/string_extension.dart';
  import 'package:wow_english/common/widgets/ow_image_widget.dart';
2eb67dd4   liangchengyou   feat:调整代码
7
  import 'package:wow_english/models/course_process_entity.dart';
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
8
9
10
11
12
13
14
15
16
17
  
  import 'bloc/topic_picture_bloc.dart';
  import 'widgets/practice_header_widget.dart';
  
  class TopicPicturePage extends StatelessWidget {
    const TopicPicturePage({super.key});
  
    @override
    Widget build(BuildContext context) {
      return BlocProvider(
2eb67dd4   liangchengyou   feat:调整代码
18
19
20
21
22
23
        create: (context) => TopicPictureBloc(
            PageController(),
            3
        )
          ..add(RequestDataEvent())
          ..add(InitMessageChannelEvent()),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
24
25
26
27
28
29
30
31
32
        child: _TopicPicturePage(),
      );
    }
  }
  
  class _TopicPicturePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return BlocListener<TopicPictureBloc,TopicPictureState>(
2eb67dd4   liangchengyou   feat:调整代码
33
34
35
36
37
        listener: (context, state){
          if (state is RequestDataState) {
            context.read<TopicPictureBloc>().add(CurrentPageIndexChangeEvent(0));
          }
        },
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
38
39
40
41
42
        child: _topicPictureView(),
      );
    }
  
    Widget _topicPictureView() => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
43
44
45
46
47
48
49
50
51
        builder: (context,state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
          return Container(
            color: Colors.white,
            child: Stack(
              children: [
                Column(
                  children: [
                    PracticeHeaderWidget(
2eb67dd4   liangchengyou   feat:调整代码
52
                      title: '${bloc.currentPage}/${bloc.entity?.topics?.length}',
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
53
54
55
56
                      onTap: (){Navigator.pop(context);},
                    ),
                    Expanded(
                      child: PageView.builder(
2eb67dd4   liangchengyou   feat:调整代码
57
                          itemCount: bloc.entity?.topics?.length,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
58
59
60
61
62
63
                          scrollDirection: Axis.horizontal,
                          controller: bloc.pageController,
                          onPageChanged: (int index) {
                            bloc.add(CurrentPageIndexChangeEvent(index));
                          },
                          itemBuilder: (BuildContext context,int index){
2eb67dd4   liangchengyou   feat:调整代码
64
65
66
67
68
69
70
71
72
73
74
                            CourseProcessTopics? topics = bloc.entity?.topics![index];
                            if (topics?.type == 1) {//听音选图
                              return _pageViewVoicePictureItemWidget(topics);
                            } else if (topics?.type == 2) {//听音选字
                              return _pageViewVoiceWordItemWidget(topics);
                            } else if (topics?.type == 3) {//看题选字
                              return _pageViewWordItemWidget(topics);
                            } else if (topics?.type == 4) {//看题选图
                              return _pageViewItemWidget(topics);
                            } else {//语音问答
                              return _voiceAnswerItem(topics);
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
                            }
                          }),
                    )
                  ],
                ),
                Positioned(
                    left: 0,
                    right: 0,
                    bottom: 0,
                    child: Image.asset('bottom_grass'.assetPng)
                )
              ],
            ),
          );
        });
  
    ///看题选图
2eb67dd4   liangchengyou   feat:调整代码
92
    Widget _pageViewItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
93
        builder: (context, state){
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
94
95
96
97
98
99
100
101
102
103
104
105
          return SafeArea(
            child: Column(
              children: [
                Text(
                    'What to do when the sentence question is very long and needs a line break',
                    softWrap: true,
                    style: TextStyle(
                        fontSize: 21.sp,
                        color: const Color(0xFF333333)
                    )
                ),
                26.verticalSpace,
2eb67dd4   liangchengyou   feat:调整代码
106
107
108
109
110
111
112
113
114
115
                SizedBox(
                  height: 143.h,
                  width: 143.w * (topics?.topicAnswerList?.length??0),
                  child: ListView.builder(
                      itemCount: topics?.topicAnswerList?.length??0,
                      scrollDirection: Axis.horizontal,
                      itemBuilder: (context,index){
                        return _decodeImageWidget(index);
                      }),
                ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
116
117
118
119
120
121
122
123
124
              ],
            ),
          );
        });
  
    Widget _decodeImageWidget(int index) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
        buildWhen: (_, s) => s is SelectItemChangeState,
        builder: (context,state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
2eb67dd4   liangchengyou   feat:调整代码
125
126
127
128
          return Container(
            padding: EdgeInsets.symmetric(horizontal: 10.w),
            child: GestureDetector(
              onTap: () => bloc.add(SelectItemEvent(index)),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
129
              child: Container(
2eb67dd4   liangchengyou   feat:调整代码
130
                padding: const EdgeInsets.all(4.5),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
131
                decoration: BoxDecoration(
2eb67dd4   liangchengyou   feat:调整代码
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
                  color: bloc.selectItem == index?const Color(0xFF00B6F1):Colors.white,
                  borderRadius: BorderRadius.circular(15),
                ),
                height: 143.h,
                width: 143.w,
                child: Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(15),
                      border: Border.all(
                          width: 1.0,
                          color: const Color(0xFF140C10)
                      ),
                      image: const DecorationImage(
                          fit: BoxFit.fitWidth,
                          image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714')
                      )
                  ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
150
151
152
153
154
155
156
                ),
              ),
            ),
          );
        });
  
    ///看题选字
2eb67dd4   liangchengyou   feat:调整代码
157
    Widget _pageViewWordItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
158
159
160
161
162
163
164
165
166
167
168
169
170
171
        builder: (context, state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
          return SafeArea(
            child: Column(
              children: [
                Text(
                    'What to do when the sentence question is very long and needs a line break',
                    softWrap: true,
                    style: TextStyle(
                        fontSize: 21.sp,
                        color: const Color(0xFF333333)
                    )
                ),
                26.verticalSpace,
2eb67dd4   liangchengyou   feat:调整代码
172
173
174
175
176
177
178
179
180
181
                SizedBox(
                  height: 143.h,
                  width: 143.w * (topics?.topicAnswerList?.length??0),
                  child: ListView.builder(
                      itemCount: topics?.topicAnswerList?.length??0,
                      scrollDirection: Axis.horizontal,
                      itemBuilder: (context,index){
                        return _decodeWordWidget(index);
                      }),
                ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
182
183
184
185
186
187
188
189
190
              ],
            ),
          );
        });
  
    Widget _decodeWordWidget(int index) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
        buildWhen: (_, s) => s is SelectItemChangeState,
        builder: (context,state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
2eb67dd4   liangchengyou   feat:调整代码
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
          return Container(
            padding: EdgeInsets.symmetric(horizontal: 10.w),
            child: GestureDetector(
              onTap: () => bloc.add(SelectItemEvent(index)),
              child: Container(
                width: 143.w,
                height: 143.h,
                padding: EdgeInsets.only(left: 13.w,right: 13.w,top: 13.h,bottom: 13.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(15),
                  border: Border.all(
                      width: 1.0,
                      color: const Color(0xFF140C10)
                  ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
206
                ),
2eb67dd4   liangchengyou   feat:调整代码
207
208
209
210
211
212
213
214
215
216
217
218
219
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Expanded(
                      child: Container(
                        alignment: Alignment.center,
                        child: Text(
                            'yellow',
                            style: TextStyle(
                                fontSize: 20.sp,
                                color: const Color(0xFF333333)
                            )
                        ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
220
221
                      ),
                    ),
2eb67dd4   liangchengyou   feat:调整代码
222
223
224
225
226
227
228
229
230
231
                    Container(
                      height: 30.h,
                      width: double.infinity,
                      decoration: BoxDecoration(
                        color: bloc.selectItem == index?const Color(0xFF00B6F1):Colors.white,
                        borderRadius: BorderRadius.circular(15.r),
                        border: Border.all(
                            width: 1.5,
                            color: const Color(0xFF140C10)
                        ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
232
                      ),
2eb67dd4   liangchengyou   feat:调整代码
233
234
235
236
237
                      alignment: Alignment.center,
                      child: Image.asset('choose'.assetPng),
                    )
                  ],
                ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
238
239
240
241
242
243
              ),
            ),
          );
        });
  
    ///听音选图
2eb67dd4   liangchengyou   feat:调整代码
244
    Widget _pageViewVoicePictureItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        builder: (context, state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
          return SafeArea(
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Image.asset('voice'.assetPng,height: 33.h,width: 30.w,),
                    10.horizontalSpace,
                    Text(
                        'yellow',
                        style: TextStyle(
                            fontSize: 20.sp,
                            color: const Color(0xFF333333)
                        )
                    )
                  ],
                ),
                26.verticalSpace,
2eb67dd4   liangchengyou   feat:调整代码
265
266
267
268
269
270
271
272
273
274
                SizedBox(
                  height: 143.h,
                  width: 163.w * (topics?.topicAnswerList?.length??0),
                  child: ListView.builder(
                      scrollDirection: Axis.horizontal,
                      itemCount: topics?.topicAnswerList?.length??0,
                      itemBuilder: (BuildContext context,int index){
                        return _decodeVoiceImageWidget(1,topics?.topicAnswerList?[index]);
                      })
                  ,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
275
276
277
278
279
280
                )
              ],
            ),
          );
        });
  
2eb67dd4   liangchengyou   feat:调整代码
281
    Widget _decodeVoiceImageWidget(int index,CourseProcessTopicsTopicAnswerList? answerList) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
282
283
284
        buildWhen: (_, s) => s is SelectItemChangeState,
        builder: (context,state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
2eb67dd4   liangchengyou   feat:调整代码
285
286
287
288
          return Container(
            padding:  EdgeInsets.symmetric(horizontal: 10.w),
            child: GestureDetector(
              onTap: () => bloc.add(SelectItemEvent(index)),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
289
              child: Container(
2eb67dd4   liangchengyou   feat:调整代码
290
                padding: const EdgeInsets.all(4.5),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
291
                decoration: BoxDecoration(
2eb67dd4   liangchengyou   feat:调整代码
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
                  color: bloc.selectItem == index?const Color(0xFF00B6F1):Colors.white,
                  borderRadius: BorderRadius.circular(15),
                ),
                height: 143.h,
                width: 143.w,
                child: Container(
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(15),
                      border: Border.all(
                          width: 1.0,
                          color: const Color(0xFF140C10)
                      ),
                      image: const DecorationImage(
                          fit: BoxFit.fitWidth,
                          image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714')
                      )
                  ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
310
311
312
313
314
315
316
                ),
              ),
            ),
          );
        });
  
    ///听音选字
2eb67dd4   liangchengyou   feat:调整代码
317
    Widget _pageViewVoiceWordItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
318
319
320
321
322
323
324
        builder: (context, state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
          return SafeArea(
            child: Column(
              children: [
                Image.asset('voice'.assetPng,height: 33.h,width: 30.w,),
                26.verticalSpace,
2eb67dd4   liangchengyou   feat:调整代码
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
                SizedBox(
                  width: 163.w * (topics?.topicAnswerList?.length??0),
                  height: 143.h,
                  child: ListView.builder(
                      itemCount: topics?.topicAnswerList?.length,
                      scrollDirection: Axis.horizontal,
                      itemBuilder: (BuildContext context,int index){
                        return _decodeVoiceWordImageWidget(index, topics!.topicAnswerList![index]);
                      }),
                ),
                // Row(
                //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //   children: [
                //     Offstage(
                //       offstage: topics.topicAnswerList!.length <= 1,
                //       child: _decodeVoiceWordImageWidget(1,topics.topicAnswerList![0]),
                //     ),
                //     Offstage(
                //       offstage: topics.topicAnswerList!.length <= 2,
                //       child: _decodeVoiceWordImageWidget(2,topics.topicAnswerList![1]),
                //     ),
                //     // Offstage(
                //     //   offstage: topics.topicAnswerList!.length <= 3,
                //     //   child: _decodeVoiceWordImageWidget(3,topics.topicAnswerList![2]),
                //     // ),
                //     // Offstage(
                //     //   offstage: topics.topicAnswerList!.length <= 4,
                //     //   child: _decodeVoiceWordImageWidget(4,topics.topicAnswerList![3]),
                //     // )
                //   ],
                // )
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
356
357
358
359
360
              ],
            ),
          );
        });
  
2eb67dd4   liangchengyou   feat:调整代码
361
    Widget _decodeVoiceWordImageWidget(int index,CourseProcessTopicsTopicAnswerList answerList) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
362
363
364
365
366
367
        buildWhen: (_, s) => s is SelectItemChangeState,
        builder: (context,state){
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
          return GestureDetector(
            onTap: () => bloc.add(SelectItemEvent(index)),
            child: Container(
2eb67dd4   liangchengyou   feat:调整代码
368
              width: 163.w,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
369
              height: 143.h,
2eb67dd4   liangchengyou   feat:调整代码
370
371
372
373
374
375
376
377
378
379
380
381
              padding: EdgeInsets.symmetric(horizontal: 10.w),
              child: Container(
                width: 143.w,
                height: 143.h,
                padding: EdgeInsets.only(left: 13.w,right: 13.w,top: 13.h,bottom: 13.h),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(15),
                  border: Border.all(
                      width: 1.0,
                      color: const Color(0xFF140C10)
                  ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
382
                ),
2eb67dd4   liangchengyou   feat:调整代码
383
384
385
386
387
388
389
390
391
392
393
394
395
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Expanded(
                      child: Container(
                        alignment: Alignment.center,
                        child: Text(
                            answerList.word??'',
                            style: TextStyle(
                                fontSize: 20.sp,
                                color: const Color(0xFF333333)
                            )
                        ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
396
397
                      ),
                    ),
2eb67dd4   liangchengyou   feat:调整代码
398
399
400
401
402
403
404
405
406
407
                    Container(
                      height: 30.h,
                      width: double.infinity,
                      decoration: BoxDecoration(
                        color: bloc.selectItem == index?const Color(0xFF00B6F1):Colors.white,
                        borderRadius: BorderRadius.circular(15.r),
                        border: Border.all(
                            width: 1.5,
                            color: const Color(0xFF140C10)
                        ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
408
                      ),
2eb67dd4   liangchengyou   feat:调整代码
409
410
411
412
413
                      alignment: Alignment.center,
                      child: Image.asset('choose'.assetPng),
                    )
                  ],
                ),
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
414
415
416
417
418
419
              ),
            ),
          );
        });
  
    ///语音问答
2eb67dd4   liangchengyou   feat:调整代码
420
    Widget _voiceAnswerItem(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
421
        builder: (context, state) {
2eb67dd4   liangchengyou   feat:调整代码
422
          final bloc = BlocProvider.of<TopicPictureBloc>(context);
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
423
          return Row(
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
424
425
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
2eb67dd4   liangchengyou   feat:调整代码
426
427
428
429
              OwImageWidget(
                name:'https://up.enterdesk.com/edpic_source/16/e7/0d/16e70d550daff77cbac31fae5e1651d4.jpg',
                height: 186.h,
                width: 186.w,
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
430
              ),
2eb67dd4   liangchengyou   feat:调整代码
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
              160.horizontalSpace,
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Image.asset(
                    'voice'.assetPng,
                    height: 52.h,
                    width: 46.w,
                  ),
                  70.verticalSpace,
                  GestureDetector(
                    onTap: () {
                      if (bloc.isVoicing) {
                        return;
                      }
                      bloc.add(VoiceXsTestEvent('Hello', 0,context.read<CacheBloc>().userEntity!.id));
                    },
                    child: Image.asset(
                      'micro_phone'.assetPng,
                      height: 75.w,
                      width: 75.w,
                    ),
                  )
                ],
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
455
456
              )
            ],
2eb67dd4   liangchengyou   feat:调整代码
457
458
          );
        });
842b7132   liangchengyou   feat:磨耳朵/练习页面调整
459
  }