Commit a434ef7b2e9406f23089ad20eebd3fa7d2f8408c

Authored by liangchengyou
1 parent d5e7df44

feat:修复绘本页闪退问题

assets/images/photo_pause.png

304 KB | W: | H:

340 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
lib/pages/reading/bloc/reading_bloc.dart
... ... @@ -90,20 +90,16 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> {
90 90 //音频播放器
91 91 audioPlayer = AudioPlayer();
92 92 audioPlayer.onPlayerStateChanged.listen((event) async {
93   - debugPrint('播放状态变化');
94 93 if (event == PlayerState.completed) {
95   - debugPrint('播放完成');
96 94 _voicePlayState = VoicePlayState.completed;
97 95 _onAudioPlayComplete();
98 96 }
99 97 if (event == PlayerState.stopped) {
100   - debugPrint('播放结束');
101 98 _voicePlayState = VoicePlayState.stop;
102 99 _onAudioPlayComplete();
103 100 }
104 101  
105 102 if (event == PlayerState.playing) {
106   - debugPrint('正在播放中');
107 103 _voicePlayState = VoicePlayState.playing;
108 104 }
109 105 if (isClosed) {
... ... @@ -261,6 +257,9 @@ class ReadingPageBloc extends Bloc<ReadingPageEvent, ReadingPageState> {
261 257 }
262 258  
263 259 CourseProcessReadings? currentPageData() {
  260 + if ((_entity?.readings?.length??0) - 1 < _currentPage) {
  261 + return null;
  262 + }
264 263 return _entity?.readings?[_currentPage];
265 264 }
266 265  
... ... @@ -338,7 +337,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
338 337 nextPage();
339 338 }
340 339  
341   - Log.d("_onAudioPlayComplete _isOriginAudioPlaying=${_isOriginAudioPlaying} _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}");
  340 + Log.d("_onAudioPlayComplete _isOriginAudioPlaying=$_isOriginAudioPlaying _voicePlayState=$_voicePlayState recordUrl=${currentPageData()?.recordUrl?.isNotEmpty}");
342 341 if (_isOriginAudioPlaying && _voicePlayState == VoicePlayState.completed && currentPageData()?.recordUrl?.isNotEmpty != true) {
343 342 ///如果刚刚完成原音播放&&录音为空,则开始录音
344 343 startRecord(currentPageData()?.word ?? '');
... ... @@ -358,7 +357,7 @@ class ReadingPageBloc extends Bloc&lt;ReadingPageEvent, ReadingPageState&gt; {
358 357 OnXSVoiceStateChangeEvent event,
359 358 Emitter<ReadingPageState> emitter
360 359 ) async {
361   - emit(XSVoiceTestState());
  360 + emitter(XSVoiceTestState());
362 361 }
363 362 }
364 363  
... ...
lib/pages/reading/reading_page.dart
... ... @@ -118,8 +118,7 @@ class _ReadingPage extends StatelessWidget {
118 118 ),
119 119  
120 120 Padding(
121   - padding: EdgeInsets.only(
122   - right: 15.w + ScreenUtil().bottomBarHeight),
  121 + padding: EdgeInsets.only(right: 15.w + ScreenUtil().bottomBarHeight),
123 122 child: GestureDetector(
124 123 onTap: () {
125 124 bloc.add(CurrentModeChangeEvent());
... ... @@ -233,13 +232,12 @@ class _ReadingPage extends StatelessWidget {
233 232 );
234 233 });
235 234  
236   - Widget _readingPagerItem(CourseProcessReadings readings) =>
237   - BlocBuilder<ReadingPageBloc, ReadingPageState>(builder: (context, state) {
  235 + Widget _readingPagerItem(CourseProcessReadings readings) => BlocBuilder<ReadingPageBloc, ReadingPageState>(
  236 + builder: (context, state) {
238 237 return Stack(
239 238 children: [
240 239 Positioned.fill(
241   - child:
242   - Image.network(readings.picUrl ?? '', fit: BoxFit.cover),
  240 + child: Image.network(readings.picUrl ?? '', fit: BoxFit.cover),
243 241 ),
244 242 ],
245 243 );
... ...