Commit 7be2176f802a6adcec03221e1ed091d023ac79dc
1 parent
0493c104
feat:课程学习和游戏专区点击防抖
Showing
1 changed file
with
64 additions
and
41 deletions
lib/pages/home/view.dart
| ... | ... | @@ -19,6 +19,7 @@ import 'package:wow_english/utils/audio_player_util.dart'; |
| 19 | 19 | |
| 20 | 20 | import '../../common/core/user_util.dart'; |
| 21 | 21 | import '../../common/dialogs/show_dialog.dart'; |
| 22 | +import '../../common/utils/click_with_music_controller.dart'; | |
| 22 | 23 | import 'bloc.dart'; |
| 23 | 24 | import 'event.dart'; |
| 24 | 25 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| ... | ... | @@ -57,6 +58,7 @@ class _HomePageView extends StatelessWidget { |
| 57 | 58 | Widget _homeView() => |
| 58 | 59 | BlocBuilder<HomeBloc, HomeState>(builder: (context, state) { |
| 59 | 60 | final bloc = BlocProvider.of<HomeBloc>(context); |
| 61 | + final clickController = ClickWithMusicController.instance; | |
| 60 | 62 | return Scaffold( |
| 61 | 63 | body: Container( |
| 62 | 64 | color: Colors.white, |
| ... | ... | @@ -77,17 +79,19 @@ class _HomePageView extends StatelessWidget { |
| 77 | 79 | child: GestureDetector( |
| 78 | 80 | onTap: () { |
| 79 | 81 | _checkPermission(() async { |
| 80 | - await AudioPlayerUtil.getInstance() | |
| 81 | - .playAudio(AudioPlayerUtilType.classTime); | |
| 82 | - pushNamed(AppRouteName.courseUnit) | |
| 83 | - .then((value) => { | |
| 84 | - if (value != null) | |
| 85 | - { | |
| 86 | - bloc.exchangeResult = | |
| 87 | - value['exchange'], | |
| 88 | - bloc.add(ExchangeSuccessEvent()) | |
| 89 | - } | |
| 90 | - }); | |
| 82 | + clickController.playMusicAndPerformAction( | |
| 83 | + context, AudioPlayerUtilType.classTime, | |
| 84 | + () async { | |
| 85 | + pushNamed(AppRouteName.courseUnit) | |
| 86 | + .then((value) => { | |
| 87 | + if (value != null) | |
| 88 | + { | |
| 89 | + bloc.exchangeResult = | |
| 90 | + value['exchange'], | |
| 91 | + bloc.add(ExchangeSuccessEvent()) | |
| 92 | + } | |
| 93 | + }); | |
| 94 | + }); | |
| 91 | 95 | }, bloc); |
| 92 | 96 | }, |
| 93 | 97 | child: Column( |
| ... | ... | @@ -116,28 +120,45 @@ class _HomePageView extends StatelessWidget { |
| 116 | 120 | builder: (context, userState) { |
| 117 | 121 | return GestureDetector( |
| 118 | 122 | onTap: () { |
| 119 | - _checkPermission(() async { | |
| 120 | - await AudioPlayerUtil.getInstance().pause(); | |
| 121 | - if (Platform.isIOS) { | |
| 122 | - await LimitingDirectionCsx.setScreenDirection(DeviceDirectionMask.Portrait); | |
| 123 | - } else { | |
| 124 | - await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); | |
| 125 | - } | |
| 126 | - Navigator.of(context).pushNamed( | |
| 127 | - AppRouteName.webView, | |
| 128 | - arguments: { | |
| 129 | - 'urlStr': AppConsts.xiaoeShopUrl, | |
| 130 | - 'webViewTitle': 'Wow精选' | |
| 131 | - }).then((value) async => { | |
| 132 | - if (Platform.isIOS) { | |
| 133 | - await LimitingDirectionCsx.setScreenDirection(DeviceDirectionMask.Landscape), | |
| 134 | - } else { | |
| 135 | - await SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]), | |
| 123 | + _checkPermission(() async { | |
| 124 | + await AudioPlayerUtil.getInstance().pause(); | |
| 125 | + if (Platform.isIOS) { | |
| 126 | + await LimitingDirectionCsx | |
| 127 | + .setScreenDirection( | |
| 128 | + DeviceDirectionMask.Portrait); | |
| 129 | + } else { | |
| 130 | + await SystemChrome | |
| 131 | + .setPreferredOrientations([ | |
| 132 | + DeviceOrientation.portraitUp, | |
| 133 | + DeviceOrientation.portraitDown | |
| 134 | + ]); | |
| 135 | + } | |
| 136 | + Navigator.of(context).pushNamed( | |
| 137 | + AppRouteName.webView, | |
| 138 | + arguments: { | |
| 139 | + 'urlStr': AppConsts.xiaoeShopUrl, | |
| 140 | + 'webViewTitle': 'Wow精选' | |
| 141 | + }).then((value) async => { | |
| 142 | + if (Platform.isIOS) | |
| 143 | + { | |
| 144 | + await LimitingDirectionCsx | |
| 145 | + .setScreenDirection( | |
| 146 | + DeviceDirectionMask | |
| 147 | + .Landscape), | |
| 148 | + } | |
| 149 | + else | |
| 150 | + { | |
| 151 | + await SystemChrome | |
| 152 | + .setPreferredOrientations([ | |
| 153 | + DeviceOrientation.landscapeLeft, | |
| 154 | + DeviceOrientation.landscapeRight | |
| 155 | + ]), | |
| 136 | 156 | }, |
| 137 | - await AudioPlayerUtil.getInstance().playAudio( | |
| 138 | - AudioPlayerUtilType.touch), | |
| 139 | - }); | |
| 140 | - }, bloc); | |
| 157 | + await AudioPlayerUtil.getInstance() | |
| 158 | + .playAudio( | |
| 159 | + AudioPlayerUtilType.touch), | |
| 160 | + }); | |
| 161 | + }, bloc); | |
| 141 | 162 | }, |
| 142 | 163 | child: Offstage( |
| 143 | 164 | offstage: AppConfigHelper.shouldHidePay() || |
| ... | ... | @@ -151,15 +172,17 @@ class _HomePageView extends StatelessWidget { |
| 151 | 172 | return GestureDetector( |
| 152 | 173 | onTap: () { |
| 153 | 174 | _checkPermission(() async { |
| 154 | - await AudioPlayerUtil.getInstance() | |
| 155 | - .playAudio( | |
| 156 | - AudioPlayerUtilType.gameTime); | |
| 157 | - pushNamed(AppRouteName.games) | |
| 158 | - .then((value) => { | |
| 159 | - AudioPlayerUtil.getInstance() | |
| 160 | - .playAudio(AudioPlayerUtilType | |
| 161 | - .touch), | |
| 162 | - }); | |
| 175 | + clickController.playMusicAndPerformAction( | |
| 176 | + context, AudioPlayerUtilType.gameTime, | |
| 177 | + () async { | |
| 178 | + pushNamed(AppRouteName.games) | |
| 179 | + .then((value) => { | |
| 180 | + AudioPlayerUtil.getInstance() | |
| 181 | + .playAudio( | |
| 182 | + AudioPlayerUtilType | |
| 183 | + .touch), | |
| 184 | + }); | |
| 185 | + }); | |
| 163 | 186 | }, bloc); |
| 164 | 187 | }, |
| 165 | 188 | child: Column( | ... | ... |