Blame view

lib/pages/repeataftercontent/repeat_after_content_page.dart 13.1 KB
08a0f5a8   liangchengyou   feat:路由方式更新
1
  import 'package:flutter/material.dart';
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
2
  import 'package:flutter_bloc/flutter_bloc.dart';
08a0f5a8   liangchengyou   feat:路由方式更新
3
4
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import 'package:wow_english/common/extension/string_extension.dart';
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
5
  import 'package:wow_english/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart';
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
6
  import 'package:wow_english/pages/repeataftercontent/widgets/repeat_after_content_dialog.dart';
08a0f5a8   liangchengyou   feat:路由方式更新
7
8
  import 'package:wow_english/route/route.dart';
  
997ea0d6   liangchengyou   feat:绘本闪退问题修复
9
  import '../../common/core/app_consts.dart';
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
10
  import '../../common/core/user_util.dart';
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
11
  import '../../models/read_content_entity.dart';
d4a7dfc4   liangchengyou   feat:逻辑调整
12
  import '../../utils/toast_util.dart';
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
13
14
  import 'widgets/repeat_video_widget.dart';
  
08a0f5a8   liangchengyou   feat:路由方式更新
15
  class RepeatAfterContentPage extends StatelessWidget {
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
16
17
18
    const RepeatAfterContentPage({super.key, this.videoFollowReadId});
  
    final String? videoFollowReadId;
08a0f5a8   liangchengyou   feat:路由方式更新
19
20
21
  
    @override
    Widget build(BuildContext context) {
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
22
23
24
25
26
27
      return BlocProvider(
        create: (context) => RepeatAfterContentBloc(videoFollowReadId ??'')
          ..add(InitBlocEvent())
          ..add(RequestDataEvent())
          ..add(XSVoiceInitEvent(
              {
997ea0d6   liangchengyou   feat:绘本闪退问题修复
28
29
30
                'appKey':AppConsts.xsAppKey,
                'service':AppConsts.xsAppService,
                'secretKey':AppConsts.xsAppSecretKey,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
31
32
33
34
35
36
37
38
39
40
41
42
              }
          )),
        child: _RepeatAfterContentPage(),
      );
    }
  }
  
  class _RepeatAfterContentPage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return BlocListener<RepeatAfterContentBloc,RepeatAfterContentState>(
        listener: (context,state){
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
43
44
45
46
47
48
49
50
          final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
          if (state is VoiceRecordStateChange) {//录音状态回调
            if (bloc.voiceRecordState == VoiceRecordState.voiceRecordEnd) {//声音录制结束
              ReadContentEntity? readContentEntity = bloc.entityList?[bloc.currentPlayIndex];
              bloc.add(XSVoiceTestEvent(readContentEntity?.word??'','0',UserUtil.getUser()!.id.toString()));
            }
            return;
          }
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
51
52
53
54
55
56
57
58
59
        },
        child: _repeatAfterContentView(),
      );
    }
  
  
    Widget _repeatAfterContentView() => BlocBuilder<RepeatAfterContentBloc,RepeatAfterContentState>(builder: (context,state){
      final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
      final String videoUrl =  bloc.entityList?.first?.videoUrl??'';
08a0f5a8   liangchengyou   feat:路由方式更新
60
61
62
63
64
      return Container(
        color: Colors.white,
        child: SafeArea(
          child: Stack(
            children: [
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
65
              ///返回
08a0f5a8   liangchengyou   feat:路由方式更新
66
              Positioned(
08a0f5a8   liangchengyou   feat:路由方式更新
67
                child: GestureDetector(
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
68
69
70
71
72
73
74
75
76
77
                  onTap: () {
                    showDialog<RepeatAfterContentDialog>(
                        context: context,
                        builder: (context){
                          return RepeatAfterContentDialog( (){
                            popPage();
                          });
                        });
                    // popPage();
                  },
08a0f5a8   liangchengyou   feat:路由方式更新
78
79
80
81
82
83
                  child: Image.asset(
                    'back_around'.assetPng,
                    height: 40.h,
                    width: 40.w,
                  ),
                ),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
84
85
86
              ),
              ///左侧视频区
              Positioned(
1e7094e3   liangchengyou   feat:适配ipad
87
                top: 40.h,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
88
89
90
91
92
93
94
95
96
97
98
                left: 20.w,
                child: Container(
                  width: 285.w,
                  height: 299.h,
                  padding: EdgeInsets.symmetric(horizontal: 50.w,vertical: 50.h),
                  decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage('video_background'.assetPng),
                        fit: BoxFit.fill
                    ),
                  ),
7d6a6ddc   liangchengyou   feat:1.0.1优化
99
                  child: videoUrl.isEmpty?Container(): RepeatVideoWidget(videoUrl: bloc.entityList?.first?.videoUrl,videoUrls: bloc.entityList??[],),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
100
101
102
103
                ),
              ),
              ///右侧操作区
              Positioned(
1e7094e3   liangchengyou   feat:适配ipad
104
105
                top: 40.h,
                left: 331.w,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                child: Container(
                  width: 240.w,
                  height: 299.h,
                  padding: EdgeInsets.only(
                      left: 67.w,
                      bottom: 40.h
                  ),
                  decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage('light_ground'.assetPng),
                        fit: BoxFit.fill
                    ),
                  ),
                  child: bloc.isRecord?_buildLongPressWidget():_buildPlayVideoWidget(),
                ),
              ),
1e7094e3   liangchengyou   feat:适配ipad
122
              ///连接
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
123
              Positioned(
1e7094e3   liangchengyou   feat:适配ipad
124
                top: 59.h,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                left: 274.w,
                child: Container(
                  width: 87.w,
                  height: 240.h,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage('and_book'.assetPng),
                        fit: BoxFit.fill
                    ),
                  ),
                ),
              ),
              ///跟读
              Positioned(
1e7094e3   liangchengyou   feat:适配ipad
139
                top: 16.h,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
140
141
142
143
144
145
146
147
148
149
                left: 65.w,
                child: Container(
                  width: 185.w,
                  height: 48.h,
                  decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage('title_ground'.assetPng),
                        fit: BoxFit.fill
                    ),
                  ),
1e7094e3   liangchengyou   feat:适配ipad
150
                  alignment: Alignment.center,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
151
152
153
154
155
156
157
158
159
160
                  child: Text(
                    'read title',
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        color: Colors.white,
                        fontSize: 21.sp
                    ),
                  ),
                ),
              ),
08a0f5a8   liangchengyou   feat:路由方式更新
161
162
163
164
            ],
          ),
        ),
      );
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
165
166
167
168
169
    });
  
    ///播放中
    Widget _buildPlayVideoWidget() {
      return BlocBuilder<RepeatAfterContentBloc,RepeatAfterContentState>(
31d42f06   liangchengyou   feat:视频跟读录音修改
170
171
172
173
174
175
          buildWhen: (previous, current) {
            if (current is ChangeVideoPlayIndexEvent) {
              return true;
            }
            return false;
          },
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
176
177
178
179
180
181
182
          builder: (context,state){
            final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
            return Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Row(
                  children: [
7d6a6ddc   liangchengyou   feat:1.0.1优化
183
184
185
186
187
188
189
                    IconButton(
                        onPressed: () => bloc.add(ChangeVideoPlayIndexEvent(false)),
                        icon: Image.asset(
                          'previous'.assetPng,
                          height: 23.h,
                          width: 23.w,
                        )
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
190
                    ),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
191
192
193
194
195
                    IconButton(
                        onPressed:() => bloc.add(VideoPlayChangeEvent()),
                        icon: Image.asset(
                          'video_pause'.assetPng,
                          height: 50.h,
7d6a6ddc   liangchengyou   feat:1.0.1优化
196
                          width: 50.h,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
197
198
                        )
                    ),
7d6a6ddc   liangchengyou   feat:1.0.1优化
199
200
201
202
203
204
205
206
                    IconButton(
                        onPressed: () => bloc.add(ChangeVideoPlayIndexEvent(true)),
                        icon: Image.asset(
                          'next'.assetPng,
                          height: 23.h,
                          width: 23.w,
                        )
                    )
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
207
208
209
210
211
212
213
214
215
216
217
218
219
                  ],
                ),
                Row(
                  children: [
                    SizedBox(
                      height: 23.h,
                      width: 23.w,
                    ),
                    10.horizontalSpace,
                    Column(
                      children: [
                        20.verticalSpace,
                        IconButton(
d4a7dfc4   liangchengyou   feat:逻辑调整
220
221
222
223
224
225
226
                            onPressed: () {
                              if (bloc.videoPlaying) {
                                showToast('视频正在播放中');
                                return;
                              }
                              bloc.add(VoiceRecordEvent());
                            },
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
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
                            icon: Image.asset(
                              'video_record'.assetPng,
                              height: 53.h,
                              width: 53.w,
                            )
                        ),
                        Text(
                          '录音',
                          style: TextStyle(
                              color: const Color(0xFF333333),
                              fontSize: 14.sp
                          ),
                        )
                      ],
                    ),
                    // Container(
                    //   height: 22.h,
                    //   width: 37.w,
                    //   decoration: BoxDecoration(
                    //       color: const Color(0xFF56CE5F),
                    //       borderRadius: BorderRadius.circular(10.r)
                    //   ),
                    //   child: Text(
                    //     '1.0x',
                    //     textAlign: TextAlign.center,
                    //     style: TextStyle(
                    //         color: Colors.white,
                    //         fontSize: 12.sp
                    //     ),
                    //   ),
                    // )
                  ],
                )
              ],
            );
          });
08a0f5a8   liangchengyou   feat:路由方式更新
263
    }
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
264
265
266
267
268
269
  
    ///长按录音
    Widget _buildLongPressWidget() => BlocBuilder<RepeatAfterContentBloc,RepeatAfterContentState>(
        builder: (context,state){
          final bloc = BlocProvider.of<RepeatAfterContentBloc>(context);
          final voiceResult = bloc.voiceTestResult;
31d42f06   liangchengyou   feat:视频跟读录音修改
270
271
272
273
274
275
276
277
          Color color;
          if (int.parse(voiceResult?['overall'].toString()??'0') >= 60 || int.parse(voiceResult?['overall'].toString()??'0') <= 75) {
            color = const Color(0xFFFF0000);
          } else if (int.parse(voiceResult?['overall'].toString()??'0') > 75 || int.parse(voiceResult?['overall'].toString()??'0') <= 85) {
            color = const Color(0xFFFFCC00);
          } else {
            color = const Color(0xFF40E04B);
          }
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
278
279
280
281
          return Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Offstage(
31d42f06   liangchengyou   feat:视频跟读录音修改
282
                offstage:!(bloc.voiceRecordState == VoiceRecordState.voiceRecordEnd && bloc.xSCheckState == XSVoiceCheckState.result),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
283
284
                child: Column(
                  children: [
31d42f06   liangchengyou   feat:视频跟读录音修改
285
286
287
288
289
290
                    Offstage(
                      offstage:int.parse(voiceResult?['overall'].toString()??'0') > 60,
                      child: Image.asset(
                        'sorrow_face'.assetPng,
                        height: 46.h,
                        width: 46.w,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
291
                      ),
31d42f06   liangchengyou   feat:视频跟读录音修改
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
                    ),
                    Offstage(
                      offstage: int.parse(voiceResult?['overall'].toString()??'0') < 60,
                      child: Container(
                        height: 45.h,
                        width: 45.h,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: color,
                            borderRadius: BorderRadius.circular(22.5.r)
                        ),
                        child: Text(
                          voiceResult?['overall'].toString()??'0',
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 17.sp
                          ),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
310
311
312
313
314
                        ),
                      ),
                    ),
                    IconButton(
                        onPressed: (){
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
315
                          bloc.add(RecordeVoicePlayEvent());
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
                        },
                        icon: Image.asset(
                          'voice_record_play'.assetPng,
                          height: 30.h,
                          width: 30.w,
                        )
                    ),
                    Text(
                      '录音',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          color: const Color(0xFF666666),
                          fontSize: 11.sp
                      ),
                    ),
                  ],
                ),
              ),
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
334
              Offstage(
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
335
336
337
338
                offstage: bloc.voiceRecordState == VoiceRecordState.voiceRecordUnkonw || bloc.xSCheckState != XSVoiceCheckState.unKnow,
                child: Container(
                  color: Colors.grey,
                  padding: EdgeInsets.symmetric(
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
339
340
                      vertical: 50.h,
                      horizontal: 50.w
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
341
342
                  ),
                  child: Text(
68dd7ba8   liangchengyou   feat:首页主题颜色+已知问题修改
343
                      bloc.voiceRecordState == VoiceRecordState.voiceRecording?'正在录音':'录音结束'
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
344
345
346
347
                  ),
                ),
              ),
              10.verticalSpace,
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
348
349
              GestureDetector(
                onTap: () => bloc.add(VoiceRecordEvent()),
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
350
                onLongPressStart: (LongPressStartDetails details) {
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
351
352
                  ///开始录音
                  bloc.add(StarRecordVoiceEvent());
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
353
354
                },
                onLongPressEnd: (LongPressEndDetails details) {
9efff6ae   liangchengyou   feat:视频跟读逻辑修改
355
356
                  ///结束录音
                  bloc.add(StopRecordVoiceEvent());
cb38bc90   liangchengyou   feat:视频跟读逻辑处理
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
                },
                child: Image.asset(
                  'video_record'.assetPng,
                  height: 78.h,
                  width: 78.w,
                ),
              ),
              Text(
                '按住录音',
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: const Color(0xFF333333),
                    fontSize: 16.sp
                ),
              ),
            ],
          );
        });
08a0f5a8   liangchengyou   feat:路由方式更新
375
  }