reading_page.dart
7.68 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
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';
import 'package:wow_english/pages/reading/widgets/ReadingModeType.dart';
import '../../common/core/user_util.dart';
import '../../models/course_process_entity.dart';
import 'bloc/reading_bloc.dart';
class ReadingPage extends StatelessWidget {
const ReadingPage({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => ReadingPageBloc(PageController())..add(RequestDataEvent()),
child: _ReadingPage(),
);
}
}
class _ReadingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocListener<ReadingPageBloc, ReadingPageState>(
listener: (context, state) {
if (state is RequestDataState) {
// context.read<TopicPictureBloc>().add(CurrentPageIndexChangeEvent(0));
print('reading RequestDataState=$state');
///刷新页面
context.read<ReadingPageBloc>().add(CurrentPageIndexChangeEvent(0));
}
},
child: _readingPageView(),
);
}
Widget _readingPageView() => BlocBuilder<ReadingPageBloc, ReadingPageState>(
buildWhen: (_, s) => s is CurrentPageIndexState,
builder: (context, state) {
final bloc = BlocProvider.of<ReadingPageBloc>(context);
return Container(
color: Colors.white,
child: Stack(
children: [
PageView.builder(
itemCount: bloc.dataCount(),
controller: bloc.pageController,
onPageChanged: (int index) {
bloc.add(CurrentPageIndexChangeEvent(index));
},
itemBuilder: (context, int index) {
return _readingPagerItem(bloc.entity!.readings![index]);
}),
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(
'${bloc.currentPage}/${bloc.dataCount()}',
style: TextStyle(fontSize: 20.sp, color: Colors.white),
),
),
Padding(
padding: EdgeInsets.only(
right: 15.w + ScreenUtil().bottomBarHeight),
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: [
GestureDetector(
onTap: () {
if (bloc.isRecording) {
return;
}
print("voice tap");
bloc.add(PlayOriginalAudioEvent(null));
},
child: Image.asset(
'voice'.assetPng,
height: 40.h,
width: 45.w,
),
),
SizedBox(
width: 10.w,
),
Expanded(
child: Text(
bloc.currentPageData()?.word ?? '',
style: TextStyle(
color: const Color(0xFF333333), fontSize: 21.sp),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)),
SizedBox(
width: 10.w,
),
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,
)),
SizedBox(
width: 10.w,
),
Visibility(
visible: false,
///todo 依据是否录过音
child: Image.asset(
'record_pause'.assetWebp,
///todo 根据播放状态切换图片
height: 33.h,
width: 33.w,
),
)
],
),
),
)
],
),
);
});
Widget _readingPagerItem(CourseProcessReadings readings) =>
BlocBuilder<ReadingPageBloc, ReadingPageState>(builder: (context, state) {
return Stack(
children: [
Image.network(readings.picUrl ?? '',
height: double.infinity, width: double.infinity),
],
);
});
}