Commit 0427feebc739acfced4278294b06fb4e6b90afc1
1 parent
42f15f6c
feat:增加播放器对页面生命周期的感知,route变化时重置ClickWithMusicController#_isPlaying,规避点击播放音乐过程中返回页面导致状态泄漏,后面点击都无法响应
Showing
4 changed files
with
40 additions
and
7 deletions
lib/app/app.dart
| ... | ... | @@ -10,6 +10,8 @@ import 'package:wow_english/pages/tab/blocs/tab_bloc.dart'; |
| 10 | 10 | import 'package:wow_english/pages/user/bloc/user_bloc.dart'; |
| 11 | 11 | import 'package:wow_english/route/route.dart'; |
| 12 | 12 | |
| 13 | +import '../route/custom_navigator_observer.dart'; | |
| 14 | + | |
| 13 | 15 | class App extends StatelessWidget { |
| 14 | 16 | const App([this._navigatorObserver]); |
| 15 | 17 | |
| ... | ... | @@ -49,7 +51,7 @@ class App extends StatelessWidget { |
| 49 | 51 | navigatorObservers: <NavigatorObserver>[ |
| 50 | 52 | // 带入ApmNavigatorObserver实例用于路由监听 |
| 51 | 53 | // 如果不带入SDK监听器将无法获知页面(PV)入栈退栈行为,错误率(Dart异常数/FlutterPV次数)将异常攀升。 |
| 52 | - _navigatorObserver ?? ApmNavigatorObserver.singleInstance | |
| 54 | + _navigatorObserver ?? ApmNavigatorObserver.singleInstance, CustomNavigatorObserver() | |
| 53 | 55 | ], |
| 54 | 56 | ), |
| 55 | 57 | )), | ... | ... |
lib/common/utils/click_with_music_controller.dart
lib/pages/module/course_module_page.dart
| ... | ... | @@ -94,12 +94,10 @@ class _LessonPageView extends StatelessWidget { |
| 94 | 94 | // color: bloc.currentPageIndex == index |
| 95 | 95 | // ? Colors.red |
| 96 | 96 | // : Colors.white, |
| 97 | - color: | |
| 98 | - parseColor(model.getSafeThemeColor()) | |
| 99 | - .withOpacity( | |
| 100 | - bloc.currentPageIndex == index | |
| 101 | - ? 1 | |
| 102 | - : 0.15), | |
| 97 | + color: parseColor(model.getSafeThemeColor()) | |
| 98 | + .withOpacity(bloc.currentPageIndex == index | |
| 99 | + ? 1 | |
| 100 | + : 0.15), | |
| 103 | 101 | borderRadius: BorderRadius.circular(5.r), |
| 104 | 102 | border: Border.all( |
| 105 | 103 | width: 0.5, | ... | ... |
lib/route/custom_navigator_observer.dart
0 → 100644
| 1 | + | |
| 2 | + | |
| 3 | +import 'package:flutter/cupertino.dart'; | |
| 4 | +import 'package:wow_english/common/utils/click_with_music_controller.dart'; | |
| 5 | +import 'package:wow_english/utils/audio_player_util.dart'; | |
| 6 | + | |
| 7 | +import '../utils/log_util.dart'; | |
| 8 | + | |
| 9 | +class CustomNavigatorObserver extends RouteObserver<PageRoute<dynamic>> { | |
| 10 | + @override | |
| 11 | + void didPush(Route route, Route? previousRoute) { | |
| 12 | + Log.d("WQF CustomNavigatorObserver didPush route=$route previousRoute=$previousRoute"); | |
| 13 | + if (route is PageRoute) { | |
| 14 | + ClickWithMusicController.instance.reset(); | |
| 15 | + } | |
| 16 | + super.didPush(route, previousRoute); | |
| 17 | + } | |
| 18 | + | |
| 19 | + @override | |
| 20 | + void didPop(Route route, Route? previousRoute) { | |
| 21 | + Log.d("WQF CustomNavigatorObserver didPop route=$route previousRoute=$previousRoute"); | |
| 22 | + if (route is PageRoute) { | |
| 23 | + ClickWithMusicController.instance.reset(); | |
| 24 | + } | |
| 25 | + super.didPop(route, previousRoute); | |
| 26 | + } | |
| 27 | + | |
| 28 | + | |
| 29 | +} | |
| 0 | 30 | \ No newline at end of file | ... | ... |