Commit d5fb5080ae49dc5e668432e540c340494b50f7fa
1 parent
5e2bbbd3
设置页添加版本号 ,播放音频冗余代码删除
Showing
5 changed files
with
62 additions
and
59 deletions
lib/pages/home/bloc.dart
| 1 | 1 | import 'package:audioplayers/audioplayers.dart'; |
| 2 | 2 | import 'package:bloc/bloc.dart'; |
| 3 | +import 'package:wow_english/common/core/user_util.dart'; | |
| 3 | 4 | import 'package:wow_english/common/extension/string_extension.dart'; |
| 4 | 5 | |
| 5 | 6 | import '../../common/core/app_config_helper.dart'; |
| ... | ... | @@ -19,22 +20,14 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> { |
| 19 | 20 | late AudioPlayer audioPlayer; |
| 20 | 21 | late AudioPlayer studyPlayer; |
| 21 | 22 | late AudioPlayer gamePlayer; |
| 22 | - @override | |
| 23 | - Future<void> close() { | |
| 24 | - audioPlayer.release(); | |
| 25 | - audioPlayer.dispose(); | |
| 26 | - studyPlayer.release(); | |
| 27 | - studyPlayer.dispose(); | |
| 28 | - gamePlayer.release(); | |
| 29 | - gamePlayer.dispose(); | |
| 30 | - return super.close(); | |
| 31 | - } | |
| 32 | 23 | |
| 33 | 24 | void _init(InitEvent event, Emitter<HomeState> emit) async { |
| 34 | - audioPlayer = AudioPlayer(playerId: 'audio'); | |
| 35 | - gamePlayer = AudioPlayer(playerId: 'game'); | |
| 36 | - studyPlayer = AudioPlayer(playerId: 'study'); | |
| 37 | - audioPlayer.play(AssetSource('welcome_to_wow'.assetMp3)); | |
| 25 | + if (UserUtil.isLogined()) { | |
| 26 | + audioPlayer = AudioPlayer(playerId: 'audio'); | |
| 27 | + gamePlayer = AudioPlayer(playerId: 'game'); | |
| 28 | + studyPlayer = AudioPlayer(playerId: 'study'); | |
| 29 | + audioPlayer.play(AssetSource('welcome_to_wow'.assetMp3)); | |
| 30 | + } | |
| 38 | 31 | await _checkUpdate(emit); |
| 39 | 32 | } |
| 40 | 33 | ... | ... |
lib/pages/home/view.dart
| ... | ... | @@ -73,15 +73,17 @@ class _HomePageView extends StatelessWidget { |
| 73 | 73 | _checkPermission(() { |
| 74 | 74 | bloc.studyPlayer |
| 75 | 75 | .play(AssetSource('class_time'.assetMp3)); |
| 76 | - pushNamed(AppRouteName.courseUnit) | |
| 77 | - .then((value) => { | |
| 78 | - if (value != null) | |
| 79 | - { | |
| 80 | - bloc.exchangeResult = | |
| 81 | - value['exchange'], | |
| 82 | - bloc.add(ExchangeSuccessEvent()) | |
| 83 | - } | |
| 84 | - }); | |
| 76 | + Future.delayed(const Duration(seconds: 1), () { | |
| 77 | + pushNamed(AppRouteName.courseUnit) | |
| 78 | + .then((value) => { | |
| 79 | + if (value != null) | |
| 80 | + { | |
| 81 | + bloc.exchangeResult = | |
| 82 | + value['exchange'], | |
| 83 | + bloc.add(ExchangeSuccessEvent()) | |
| 84 | + } | |
| 85 | + }); | |
| 86 | + }); | |
| 85 | 87 | }, bloc); |
| 86 | 88 | }, |
| 87 | 89 | child: Column( | ... | ... |
lib/pages/section/bloc/section_bloc.dart
| ... | ... | @@ -65,22 +65,18 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { |
| 65 | 65 | on<RequestEnterClassEvent>(_requestEnterClass); |
| 66 | 66 | on<RequestVideoLessonEvent>(_requestVideoLesson); |
| 67 | 67 | on<CurrentUnitIndexChangeEvent>(_pageControllerChange); |
| 68 | - on<InitEvent>(_init); | |
| 69 | - on<InitBlocEvent>((event, emit) { | |
| 70 | - // audioPlayer = AudioPlayer(playerId: 'section'); | |
| 71 | - // backgroundPlayer = AudioPlayer(playerId: 'back'); | |
| 72 | - // backgroundPlayer.onPlayerStateChanged.listen((event) async { | |
| 73 | - // if (event == PlayerState.completed) { | |
| 74 | - // debugPrint('播放结束'); | |
| 75 | - // backgroundPlayer | |
| 76 | - // .play(AssetSource('count_with_me_instrumental'.assetMp3)); | |
| 77 | - // } | |
| 78 | - // }); | |
| 79 | - // audioPlayer.onPlayerStateChanged.listen((event) async { | |
| 80 | - // if (event == PlayerState.completed) { | |
| 81 | - // debugPrint('播放结束'); | |
| 82 | - // } | |
| 83 | - // }); | |
| 68 | + on<InitEvent>((event, emit) { | |
| 69 | + audioPlayer = AudioPlayer(playerId: 'section'); | |
| 70 | + backgroundPlayer = AudioPlayer(playerId: 'back'); | |
| 71 | + backgroundPlayer.play(AssetSource('count_with_me_instrumental'.assetMp3)); | |
| 72 | + | |
| 73 | + backgroundPlayer.onPlayerStateChanged.listen((event) async { | |
| 74 | + if (event == PlayerState.completed) { | |
| 75 | + // 播放结束再次播放 | |
| 76 | + backgroundPlayer | |
| 77 | + .play(AssetSource('count_with_me_instrumental'.assetMp3)); | |
| 78 | + } | |
| 79 | + }); | |
| 84 | 80 | }); |
| 85 | 81 | } |
| 86 | 82 | @override |
| ... | ... | @@ -92,12 +88,6 @@ class SectionBloc extends Bloc<SectionEvent, SectionState> { |
| 92 | 88 | return super.close(); |
| 93 | 89 | } |
| 94 | 90 | |
| 95 | - void _init(InitEvent event, Emitter<SectionState> emit) async { | |
| 96 | - audioPlayer = AudioPlayer(playerId: 'section'); | |
| 97 | - // backgroundPlayer = AudioPlayer(playerId: 'back'); | |
| 98 | - // backgroundPlayer.play(AssetSource('count_with_me_instrumental'.assetMp3)); | |
| 99 | - } | |
| 100 | - | |
| 101 | 91 | void _requestSectionsData( |
| 102 | 92 | RequestDataEvent event, Emitter<SectionState> emitter) async { |
| 103 | 93 | try { | ... | ... |
lib/pages/section/bloc/section_event.dart
lib/pages/user/setting/setting_page.dart
| 1 | 1 | import 'package:flutter/material.dart'; |
| 2 | 2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 3 | +import 'package:package_info_plus/package_info_plus.dart'; | |
| 3 | 4 | import 'package:wow_english/common/widgets/we_app_bar.dart'; |
| 4 | 5 | |
| 5 | 6 | import '../../../route/route.dart'; |
| ... | ... | @@ -9,14 +10,30 @@ class SettingPage extends StatefulWidget { |
| 9 | 10 | |
| 10 | 11 | @override |
| 11 | 12 | State<StatefulWidget> createState() { |
| 12 | - return SettingPageState(); | |
| 13 | + return SettingPageState(); | |
| 13 | 14 | } |
| 14 | 15 | } |
| 15 | 16 | |
| 16 | 17 | class SettingPageState extends State<SettingPage> { |
| 18 | + String? _version; | |
| 19 | + String? _buildNum; | |
| 20 | + @override | |
| 21 | + void initState() { | |
| 22 | + super.initState(); | |
| 23 | + _retrieveVersionInfo(); | |
| 24 | + } | |
| 25 | + | |
| 26 | + Future<void> _retrieveVersionInfo() async { | |
| 27 | + PackageInfo packageInfo = await PackageInfo.fromPlatform(); | |
| 28 | + setState(() { | |
| 29 | + _version = packageInfo.version; | |
| 30 | + _buildNum = packageInfo.buildNumber; | |
| 31 | + }); | |
| 32 | + } | |
| 33 | + | |
| 17 | 34 | @override |
| 18 | 35 | Widget build(BuildContext context) { |
| 19 | - return Scaffold( | |
| 36 | + return Scaffold( | |
| 20 | 37 | appBar: const WEAppBar( |
| 21 | 38 | titleText: '设置', |
| 22 | 39 | ), |
| ... | ... | @@ -28,17 +45,18 @@ class SettingPageState extends State<SettingPage> { |
| 28 | 45 | child: ListView( |
| 29 | 46 | children: [ |
| 30 | 47 | 34.verticalSpace, |
| 31 | - _buildItemWidget('注销账号', onPress: (){ | |
| 48 | + _buildItemWidget('注销账号', onPress: () { | |
| 32 | 49 | pushNamed(AppRouteName.deleteAccount); |
| 33 | 50 | }), |
| 34 | 51 | 12.verticalSpace, |
| 35 | - _buildItemWidget('清除缓存', onPress: (){ | |
| 36 | - | |
| 37 | - }), | |
| 52 | + _buildItemWidget('清除缓存', onPress: () {}), | |
| 38 | 53 | 12.verticalSpace, |
| 39 | - _buildItemWidget('帮助与反馈', onPress: (){ | |
| 54 | + _buildItemWidget('帮助与反馈', onPress: () { | |
| 40 | 55 | pushNamed(AppRouteName.reBack); |
| 41 | 56 | }), |
| 57 | + 12.verticalSpace, | |
| 58 | + _buildItemWidget('Version: $_version Build:$_buildNum', | |
| 59 | + onPress: () {}), | |
| 42 | 60 | ], |
| 43 | 61 | ), |
| 44 | 62 | ), |
| ... | ... | @@ -46,13 +64,15 @@ class SettingPageState extends State<SettingPage> { |
| 46 | 64 | ), |
| 47 | 65 | ); |
| 48 | 66 | } |
| 49 | - | |
| 50 | - Widget _buildItemWidget(String text,{VoidCallback? onPress}) { | |
| 67 | + | |
| 68 | + Widget _buildItemWidget(String text, {VoidCallback? onPress}) { | |
| 51 | 69 | return OutlinedButton( |
| 52 | 70 | onPressed: () => onPress?.call(), |
| 53 | 71 | style: ButtonStyle( |
| 54 | - side: MaterialStateProperty.all(BorderSide(color: const Color(0xFF140C10), width: 1.5.w)), | |
| 55 | - shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.r))), | |
| 72 | + side: MaterialStateProperty.all( | |
| 73 | + BorderSide(color: const Color(0xFF140C10), width: 1.5.w)), | |
| 74 | + shape: MaterialStateProperty.all( | |
| 75 | + RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.r))), | |
| 56 | 76 | minimumSize: MaterialStateProperty.all(Size(double.infinity, 58.h)), |
| 57 | 77 | backgroundColor: MaterialStateProperty.all(Colors.white), |
| 58 | 78 | ), |
| ... | ... | @@ -66,4 +86,4 @@ class SettingPageState extends State<SettingPage> { |
| 66 | 86 | ), |
| 67 | 87 | ); |
| 68 | 88 | } |
| 69 | -} | |
| 70 | 89 | \ No newline at end of file |
| 90 | +} | ... | ... |