Blame view

lib/pages/reading/reading_page.dart 9.7 KB
1dc46cf7   吴启风   feat:绘本ui
1
2
3
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:flutter_screenutil/flutter_screenutil.dart';
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
4
  import 'package:percent_indicator/linear_percent_indicator.dart';
1dc46cf7   吴启风   feat:绘本ui
5
  import 'package:wow_english/common/extension/string_extension.dart';
2a427e12   吴启风   feat:绘本静态ui基本完成
6
  import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart';
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
7
  import 'package:wow_english/pages/reading/widgets/reading_dialog_widget.dart';
56e2ae5a   liangchengyou   feat:绘本添加回调数据
8
  import 'package:wow_english/route/route.dart';
1dc46cf7   吴启风   feat:绘本ui
9
  
6b0947ca   吴启风   feat:绘本增加initVoic...
10
  import '../../common/core/app_consts.dart';
a506beff   吴启风   feat:先声sdk方法找不到问题...
11
  import '../../common/core/user_util.dart';
c623c7b2   吴启风   feat:语音跟读作答结果动效&语音
12
  import '../../common/widgets/recorder_widget.dart';
b81332ca   吴启风   feat:喇叭组件替换
13
  import '../../common/widgets/speaker_widget.dart';
a506beff   吴启风   feat:先声sdk方法找不到问题...
14
  import '../../models/course_process_entity.dart';
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
15
  import '../../utils/log_util.dart';
1dc46cf7   吴启风   feat:绘本ui
16
17
  import 'bloc/reading_bloc.dart';
  
4d8b0da4   吴启风   feat:绘本跟读底部ui优化
18
  ///绘本页
2a427e12   吴启风   feat:绘本静态ui基本完成
19
  class ReadingPage extends StatelessWidget {
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
20
    const ReadingPage({super.key, this.courseLessonId, this.moduleColor});
53e9e6db   吴启风   feat:绘本语音评测逻辑
21
22
  
    final String? courseLessonId;
1dc46cf7   吴启风   feat:绘本ui
23
  
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
24
25
    final Color? moduleColor;
  
1dc46cf7   吴启风   feat:绘本ui
26
27
28
    @override
    Widget build(BuildContext context) {
      return BlocProvider(
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
29
30
31
32
33
34
35
36
37
38
        create: (_) => ReadingPageBloc(
            context, PageController(), courseLessonId ?? '', moduleColor)
          ..add(InitBlocEvent())
          ..add(RequestDataEvent())
          ..add(XSVoiceInitEvent({
            'appKey': AppConsts.xsAppKey,
            'service': AppConsts.xsAppService,
            'secretKey': AppConsts.xsAppSecretKey,
            'userId': UserUtil.getUser()!.id.toString(),
          })),
1dc46cf7   吴启风   feat:绘本ui
39
40
41
42
43
44
45
46
47
        child: _ReadingPage(),
      );
    }
  }
  
  class _ReadingPage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return BlocListener<ReadingPageBloc, ReadingPageState>(
a506beff   吴启风   feat:先声sdk方法找不到问题...
48
        listener: (context, state) {
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
49
          Log.d('reading BlocListener=$state');
a506beff   吴启风   feat:先声sdk方法找不到问题...
50
          if (state is RequestDataState) {
a506beff   吴启风   feat:先声sdk方法找不到问题...
51
52
53
            ///刷新页面
            context.read<ReadingPageBloc>().add(CurrentPageIndexChangeEvent(0));
          }
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
54
55
56
57
58
59
60
61
          if (state is FeedbackState) {
            showDialog<ReadingDialog>(
                context: context,
                barrierDismissible: false,
                builder: (context) {
                  return const ReadingDialog();
                });
          }
a506beff   吴启风   feat:先声sdk方法找不到问题...
62
        },
2a427e12   吴启风   feat:绘本静态ui基本完成
63
        child: _readingPageView(),
1dc46cf7   吴启风   feat:绘本ui
64
65
66
      );
    }
  
82c8633c   biao   音频添加 页面优化
67
68
    Widget _readingPageView() =>
        BlocBuilder<ReadingPageBloc, ReadingPageState>(builder: (context, state) {
1dc46cf7   吴启风   feat:绘本ui
69
70
71
72
73
          final bloc = BlocProvider.of<ReadingPageBloc>(context);
          return Container(
            color: Colors.white,
            child: Stack(
              children: [
2a427e12   吴启风   feat:绘本静态ui基本完成
74
                PageView.builder(
a506beff   吴启风   feat:先声sdk方法找不到问题...
75
                    itemCount: bloc.dataCount(),
2a427e12   吴启风   feat:绘本静态ui基本完成
76
77
78
79
80
                    controller: bloc.pageController,
                    onPageChanged: (int index) {
                      bloc.add(CurrentPageIndexChangeEvent(index));
                    },
                    itemBuilder: (context, int index) {
a506beff   吴启风   feat:先声sdk方法找不到问题...
81
                      return _readingPagerItem(bloc.entity!.readings![index]);
2a427e12   吴启风   feat:绘本静态ui基本完成
82
83
84
                    }),
                Container(
                  color: Colors.transparent,
5b923179   吴启风   feat:导航栏优化
85
                  height: kToolbarHeight,
2a427e12   吴启风   feat:绘本静态ui基本完成
86
87
88
89
90
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Padding(
                        padding:
82c8633c   biao   音频添加 页面优化
91
                            EdgeInsets.only(left: ScreenUtil().bottomBarHeight),
2a427e12   吴启风   feat:绘本静态ui基本完成
92
93
                        child: IconButton(
                            onPressed: () {
82c8633c   biao   音频添加 页面优化
94
95
96
97
98
                              popPage(data: {
                                'currentStep': bloc.currentPage,
                                'courseLessonId': bloc.courseLessonId,
                                'isCompleted': bloc.isLastPage(),
                              });
2a427e12   吴启风   feat:绘本静态ui基本完成
99
100
101
                            },
                            icon: Image.asset(
                              'back_around'.assetPng,
5b923179   吴启风   feat:导航栏优化
102
103
                              width: 40.w,
                              height: 40.h,
2a427e12   吴启风   feat:绘本静态ui基本完成
104
105
106
                            )),
                      ),
                      Container(
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
107
108
                        height: 10.h,
                        width: 150.w,
2a427e12   吴启风   feat:绘本静态ui基本完成
109
                        alignment: Alignment.center,
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
110
111
112
113
114
115
116
117
118
119
120
                        child: LinearPercentIndicator(
                          animation: true,
                          lineHeight: 10.h,
                          animationDuration: 250,
                          animateFromLastPercent: true,
                          percent: bloc.dataCount() > 0
                              ? bloc.currentPage / bloc.dataCount()
                              : 0,
                          // center: Text('$progress/$total}'),
                          barRadius: const Radius.circular(5),
                          progressColor: bloc.moduleColor,
2a427e12   吴启风   feat:绘本静态ui基本完成
121
122
123
124
                        ),
                      ),
  
                      Padding(
a506beff   吴启风   feat:先声sdk方法找不到问题...
125
126
                        padding: EdgeInsets.only(
                            right: 15.w + ScreenUtil().bottomBarHeight),
2a427e12   吴启风   feat:绘本静态ui基本完成
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
                        child: GestureDetector(
                          onTap: () {
                            bloc.add(CurrentModeChangeEvent());
                          },
                          child: SizedBox(
                            height: 40.h,
                            child: Container(
                              decoration: BoxDecoration(
                                image: DecorationImage(
                                    image: AssetImage('bg_reading_mode'.assetPng),
                                    fit: BoxFit.fill),
                              ),
                              alignment: Alignment.center,
                              padding: EdgeInsets.symmetric(horizontal: 10.w),
                              child: Text(
                                bloc.currentMode == ReadingModeType.auto
                                    ? '设为手动'
                                    : '设为自动',
                                style: TextStyle(fontSize: 14.5.sp),
                              ),
                            ),
                          ),
                        ),
                      ),
  
                      // ScreenUtil().bottomBarHeight.horizontalSpace,
                    ],
                  ),
                ),
                Align(
                  alignment: Alignment.bottomLeft,
                  child: Container(
fd737d6a   吴启风   feat:绘本作答结果以单词为单位...
159
                    color: const Color(0xCCFFFFFF),
2a427e12   吴启风   feat:绘本静态ui基本完成
160
161
                    child: Row(
                      children: [
5e2bbbd3   biao   添加音频
162
                        5.horizontalSpace,
b81332ca   吴启风   feat:喇叭组件替换
163
164
165
166
167
168
169
170
171
                        SpeakerWidget(
                          isPlaying:
                              bloc.voicePlayState == VoicePlayState.playing &&
                                  bloc.isOriginAudioPlaying,
                          // 控制动画播放
                          isClickable: !bloc.isRecording,
                          // 控制是否可点击
                          width: 42.w,
                          height: 42.w,
a506beff   吴启风   feat:先声sdk方法找不到问题...
172
                          onTap: () {
a506beff   吴启风   feat:先声sdk方法找不到问题...
173
174
                            bloc.add(PlayOriginalAudioEvent(null));
                          },
2a427e12   吴启风   feat:绘本静态ui基本完成
175
176
177
178
179
                        ),
                        SizedBox(
                          width: 10.w,
                        ),
                        Expanded(
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
180
181
182
183
                          child: RichText(
                            text: TextSpan(
                              style: DefaultTextStyle.of(context).style,
                              children: bloc.displayContent(),
fd737d6a   吴启风   feat:绘本作答结果以单词为单位...
184
                            ),
d1ab5cb2   吴启风   feat:绘本跟读页上方进度信息改...
185
186
187
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                          ),
fd737d6a   吴启风   feat:绘本作答结果以单词为单位...
188
                        ),
2a427e12   吴启风   feat:绘本静态ui基本完成
189
190
191
                        SizedBox(
                          width: 10.w,
                        ),
c623c7b2   吴启风   feat:语音跟读作答结果动效&语音
192
193
                        RecorderWidget(
                          isPlaying: bloc.isRecording,
457ac447   吴启风   feat:代码优化-空条件调用
194
195
                          width: 54.w,
                          height: 54.w,
c623c7b2   吴启风   feat:语音跟读作答结果动效&语音
196
197
198
199
                          onTap: () {
                            if (bloc.isRecording) {
                              bloc.add(XSVoiceStopEvent());
                            } else {
b81332ca   吴启风   feat:喇叭组件替换
200
201
                              bloc.add(XSVoiceStartEvent(bloc.readingContent(),
                                  '0', UserUtil.getUser()?.id.toString()));
c623c7b2   吴启风   feat:语音跟读作答结果动效&语音
202
203
204
                            }
                          },
                        ),
1de82c6c   吴启风   feat:绘本跟读录音播放组件用回...
205
206
207
208
209
210
211
212
213
214
215
216
217
                        GestureDetector(
                            onTap: () {
                              if (bloc.isRecording) {
                                return;
                              }
                              bloc.add(PlayRecordAudioEvent());
                            },
                            child: Visibility(
                              visible: bloc.currentPageData()?.recordUrl != null,
                              child: Image.asset(
                                bloc.isRecordAudioPlaying
                                    ? 'record_pause'.assetWebp
                                    : 'record_play'.assetWebp,
457ac447   吴启风   feat:代码优化-空条件调用
218
219
                                height: 35.h,
                                width: 35.h,
1de82c6c   吴启风   feat:绘本跟读录音播放组件用回...
220
221
222
223
224
225
226
227
228
229
230
                              ),
                            )),
                        // RecorderPlaybackWidget(
                        //   isClickable: !bloc.isRecording && bloc.currentPageData()?.recordUrl != null,
                        //   isPlaying: bloc.isRecordAudioPlaying,
                        //   width: 42.w,
                        //   height: 42.w,
                        //   onTap: () {
                        //     bloc.add(PlayRecordAudioEvent());
                        //   },
                        // )
457ac447   吴启风   feat:代码优化-空条件调用
231
232
233
                        SizedBox(
                          width: 10.w,
                        )
2a427e12   吴启风   feat:绘本静态ui基本完成
234
                      ],
1dc46cf7   吴启风   feat:绘本ui
235
                    ),
2a427e12   吴启风   feat:绘本静态ui基本完成
236
                  ),
1dc46cf7   吴启风   feat:绘本ui
237
238
239
240
241
242
                )
              ],
            ),
          );
        });
  
a506beff   吴启风   feat:先声sdk方法找不到问题...
243
    Widget _readingPagerItem(CourseProcessReadings readings) =>
2a427e12   吴启风   feat:绘本静态ui基本完成
244
245
        BlocBuilder<ReadingPageBloc, ReadingPageState>(builder: (context, state) {
          return Stack(
1dc46cf7   吴启风   feat:绘本ui
246
            children: [
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
247
              Positioned.fill(
82c8633c   biao   音频添加 页面优化
248
                child: Image.network(readings.picUrl ?? '', fit: BoxFit.cover),
065022b7   吴启风   feat:绘本评测反馈弹窗+原音播...
249
              ),
1dc46cf7   吴启风   feat:绘本ui
250
251
252
253
            ],
          );
        });
  }