Blame view

lib/pages/reading/reading_page.dart 7.68 KB
1dc46cf7   吴启风   feat:绘本ui
1
2
3
4
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import 'package:wow_english/common/extension/string_extension.dart';
2a427e12   吴启风   feat:绘本静态ui基本完成
5
  import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart';
1dc46cf7   吴启风   feat:绘本ui
6
  
a506beff   吴启风   feat:先声sdk方法找不到问题...
7
8
  import '../../common/core/user_util.dart';
  import '../../models/course_process_entity.dart';
1dc46cf7   吴启风   feat:绘本ui
9
10
  import 'bloc/reading_bloc.dart';
  
2a427e12   吴启风   feat:绘本静态ui基本完成
11
12
  class ReadingPage extends StatelessWidget {
    const ReadingPage({super.key});
1dc46cf7   吴启风   feat:绘本ui
13
14
15
16
  
    @override
    Widget build(BuildContext context) {
      return BlocProvider(
a506beff   吴启风   feat:先声sdk方法找不到问题...
17
        create: (_) => ReadingPageBloc(PageController())..add(RequestDataEvent()),
1dc46cf7   吴启风   feat:绘本ui
18
19
20
21
22
23
24
25
26
        child: _ReadingPage(),
      );
    }
  }
  
  class _ReadingPage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return BlocListener<ReadingPageBloc, ReadingPageState>(
a506beff   吴启风   feat:先声sdk方法找不到问题...
27
28
29
30
31
32
33
34
35
        listener: (context, state) {
          if (state is RequestDataState) {
            // context.read<TopicPictureBloc>().add(CurrentPageIndexChangeEvent(0));
            print('reading RequestDataState=$state');
  
            ///刷新页面
            context.read<ReadingPageBloc>().add(CurrentPageIndexChangeEvent(0));
          }
        },
2a427e12   吴启风   feat:绘本静态ui基本完成
36
        child: _readingPageView(),
1dc46cf7   吴启风   feat:绘本ui
37
38
39
      );
    }
  
2a427e12   吴启风   feat:绘本静态ui基本完成
40
41
42
    Widget _readingPageView() => BlocBuilder<ReadingPageBloc, ReadingPageState>(
        buildWhen: (_, s) => s is CurrentPageIndexState,
        builder: (context, state) {
1dc46cf7   吴启风   feat:绘本ui
43
44
45
46
47
          final bloc = BlocProvider.of<ReadingPageBloc>(context);
          return Container(
            color: Colors.white,
            child: Stack(
              children: [
2a427e12   吴启风   feat:绘本静态ui基本完成
48
                PageView.builder(
a506beff   吴启风   feat:先声sdk方法找不到问题...
49
                    itemCount: bloc.dataCount(),
2a427e12   吴启风   feat:绘本静态ui基本完成
50
51
52
53
54
                    controller: bloc.pageController,
                    onPageChanged: (int index) {
                      bloc.add(CurrentPageIndexChangeEvent(index));
                    },
                    itemBuilder: (context, int index) {
a506beff   吴启风   feat:先声sdk方法找不到问题...
55
                      return _readingPagerItem(bloc.entity!.readings![index]);
2a427e12   吴启风   feat:绘本静态ui基本完成
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
                    }),
                Container(
                  color: Colors.transparent,
                  height: 60.h,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Padding(
                        padding:
                            EdgeInsets.only(left: ScreenUtil().bottomBarHeight),
                        child: IconButton(
                            onPressed: () {
                              Navigator.pop(context);
                            },
                            icon: Image.asset(
                              'back_around'.assetPng,
                              width: 40,
                              height: 40,
                            )),
                      ),
                      Container(
                        height: 32.h,
                        padding: EdgeInsets.symmetric(horizontal: 27.w),
                        decoration: BoxDecoration(
                          color: const Color(0xFF00B6F1),
                          borderRadius: BorderRadius.circular(15.r),
                          border: Border.all(
                            width: 1.0,
                            color: const Color(0xFF140C10),
                          ),
                        ),
                        alignment: Alignment.center,
                        child: Text(
a506beff   吴启风   feat:先声sdk方法找不到问题...
89
                          '${bloc.currentPage}/${bloc.dataCount()}',
2a427e12   吴启风   feat:绘本静态ui基本完成
90
91
92
93
94
                          style: TextStyle(fontSize: 20.sp, color: Colors.white),
                        ),
                      ),
  
                      Padding(
a506beff   吴启风   feat:先声sdk方法找不到问题...
95
96
                        padding: EdgeInsets.only(
                            right: 15.w + ScreenUtil().bottomBarHeight),
2a427e12   吴启风   feat:绘本静态ui基本完成
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
                        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(
                    color: const Color(0x4DFFFFFF),
                    margin: EdgeInsets.symmetric(horizontal: 10.w),
                    child: Row(
                      children: [
a506beff   吴启风   feat:先声sdk方法找不到问题...
133
134
135
136
137
138
139
140
141
142
143
144
145
                        GestureDetector(
                          onTap: () {
                            if (bloc.isRecording) {
                              return;
                            }
                            print("voice tap");
                            bloc.add(PlayOriginalAudioEvent(null));
                          },
                          child: Image.asset(
                            'voice'.assetPng,
                            height: 40.h,
                            width: 45.w,
                          ),
2a427e12   吴启风   feat:绘本静态ui基本完成
146
147
148
149
150
151
                        ),
                        SizedBox(
                          width: 10.w,
                        ),
                        Expanded(
                            child: Text(
a506beff   吴启风   feat:先声sdk方法找不到问题...
152
                          bloc.currentPageData()?.word ?? '',
2a427e12   吴启风   feat:绘本静态ui基本完成
153
154
155
156
157
158
159
160
                          style: TextStyle(
                              color: const Color(0xFF333333), fontSize: 21.sp),
                          maxLines: 2,
                          overflow: TextOverflow.ellipsis,
                        )),
                        SizedBox(
                          width: 10.w,
                        ),
a506beff   吴启风   feat:先声sdk方法找不到问题...
161
162
163
164
165
166
167
168
169
170
171
172
                        GestureDetector(
                            onTap: () {
                              if (bloc.isRecording) {
                                return;
                              }
                              bloc.add(XSVoiceTestEvent(bloc.currentPageData()?.word??'', '0',UserUtil.getUser()!.id.toString()));
                            },
                            child: Image.asset(
                              'micro_phone'.assetPng,
                              height: 47.h,
                              width: 47.w,
                            )),
2a427e12   吴启风   feat:绘本静态ui基本完成
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
                        SizedBox(
                          width: 10.w,
                        ),
                        Visibility(
                          visible: false,
  
                          ///todo 依据是否录过音
                          child: Image.asset(
                            'record_pause'.assetWebp,
  
                            ///todo 根据播放状态切换图片
                            height: 33.h,
                            width: 33.w,
                          ),
                        )
                      ],
1dc46cf7   吴启风   feat:绘本ui
189
                    ),
2a427e12   吴启风   feat:绘本静态ui基本完成
190
                  ),
1dc46cf7   吴启风   feat:绘本ui
191
192
193
194
195
196
                )
              ],
            ),
          );
        });
  
a506beff   吴启风   feat:先声sdk方法找不到问题...
197
    Widget _readingPagerItem(CourseProcessReadings readings) =>
2a427e12   吴启风   feat:绘本静态ui基本完成
198
199
        BlocBuilder<ReadingPageBloc, ReadingPageState>(builder: (context, state) {
          return Stack(
1dc46cf7   吴启风   feat:绘本ui
200
            children: [
a506beff   吴启风   feat:先声sdk方法找不到问题...
201
202
              Image.network(readings.picUrl ?? '',
                  height: double.infinity, width: double.infinity),
1dc46cf7   吴启风   feat:绘本ui
203
204
205
206
            ],
          );
        });
  }