From b90a1518bad80adb31be3f058759242e5f0d6021 Mon Sep 17 00:00:00 2001 From: lcy <2503978335@qq.com> Date: Thu, 29 Jun 2023 11:50:46 +0800 Subject: [PATCH] feat:练习接口逻辑完成 --- ios/Runner/XSMessageMehtodChannel.swift | 28 +++++++++++++++------------- lib/pages/home/home_page.dart | 3 ++- lib/pages/practice/bloc/topic_picture_bloc.dart | 35 +++++++++++++++++++++++++++++------ lib/pages/practice/bloc/topic_picture_event.dart | 4 ++-- lib/pages/practice/topic_picture_page.dart | 68 +++++++++++++++++++++++++++++++++++++++----------------------------- 5 files changed, 87 insertions(+), 51 deletions(-) diff --git a/ios/Runner/XSMessageMehtodChannel.swift b/ios/Runner/XSMessageMehtodChannel.swift index 948fc96..700427b 100644 --- a/ios/Runner/XSMessageMehtodChannel.swift +++ b/ios/Runner/XSMessageMehtodChannel.swift @@ -21,16 +21,18 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { //配置评测信息 func setEvaluateConfig(dict:Dictionary) { - let appKey = dict["appKey"] as? String - let secretKey = dict["secretKey"] as? String - let userId = dict.keys.contains("userId") ? dict["userId"] as! String:"" - let frontTime = dict["frontTime"] as? TimeInterval - let backTime = dict["frontTime"] as? TimeInterval + let appKey = dict["appKey"] as? String ?? "" + let secretKey = dict["secretKey"] as? String ?? "" + let userId = dict["userId"] as? String ?? "guest" + let frontTime = dict["frontTime"] as? String ?? "3" + let backTime = dict["frontTime"] as? String ?? "3" let config = SSOralEvaluatingManagerConfig.init() + config.vad = true + config.isOutputLog = false config.appKey = appKey //"a418" config.secretKey = secretKey //"1a16f31f2611bf32fb7b3fc38f5b2c81"' - config.frontTime = frontTime ?? 3 - config.backTime = backTime ?? 3 + config.frontTime = Double(frontTime)! + config.backTime = Double(backTime)! SSOralEvaluatingManager.register(config) SSOralEvaluatingManager.share().register(.line, userId: userId) SSOralEvaluatingManager.share().delegate = self @@ -38,12 +40,12 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { //开始评测 func evaluateVioce(dict:Dictionary) { - let text = dict["word"] as! String - let type = dict["type"] as! Int - let userId = dict["userId"] as! String + let text = dict["word"] as? String ?? "" + let type = dict["type"] as? String ?? "0" + let userId = dict["userId"] as? String ?? "guest" let config = SSOralEvaluatingConfig() config.oralContent = text - if (type == 0) { + if (type == "0") { config.oralType = .word } else { config.oralType = .sentence @@ -79,7 +81,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { */ func oralEvaluatingDidStart() { print("评测开始") - messageChannel!.invokeMethod("voiceStart", arguments: nil) +// messageChannel!.invokeMethod("voiceStart", arguments: nil) } /** @@ -87,7 +89,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate { */ func oralEvaluatingDidStop() { print("评测结束") - messageChannel!.invokeMethod("voiceEnd",arguments: nil) +// messageChannel!.invokeMethod("voiceEnd",arguments: nil) } /** diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 34de2f6..0bfff2b 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -37,7 +37,8 @@ class _HomePageView extends StatelessWidget { } else if (type == HeaderActionType.shop) { Navigator.of(AppRouter.context).pushNamed(AppRouteName.shop); } else if (type == HeaderActionType.user) { - Navigator.of(AppRouter.context).pushNamed(AppRouteName.user); + // Navigator.of(AppRouter.context).pushNamed(AppRouteName.user); + Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic); } else { // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic); } diff --git a/lib/pages/practice/bloc/topic_picture_bloc.dart b/lib/pages/practice/bloc/topic_picture_bloc.dart index 465d58e..af3c597 100644 --- a/lib/pages/practice/bloc/topic_picture_bloc.dart +++ b/lib/pages/practice/bloc/topic_picture_bloc.dart @@ -50,17 +50,38 @@ class TopicPictureBloc extends Bloc { //音频播放器 audioPlayer = AudioPlayer(); audioPlayer.onPlayerStateChanged.listen((event) { - if (event == PlayerState.stopped) { + if (event == PlayerState.completed) { + if (kDebugMode) { + print('播放完成'); - } + }} }); methodChannel = const MethodChannel('wow_english/sing_sound_method_channely'); - methodChannel.invokeMethod('initVoiceSdk',{}); methodChannel.setMethodCallHandler((call) async { - if (call.method == 'voiceResult') {//评测结束 + if (call.method == 'voiceResult') {//评测结果 add(XSVoiceResultEvent(call.arguments)); + return; + } + + if (call.method == 'voiceStart') {//评测开始 + if (kDebugMode) { + print('评测开始'); + } + return; + } + + if (call.method == 'voiceEnd') {//评测结束 + if (kDebugMode) { + print('评测结束'); + } + return; + } + + if (call.method == 'voiceFail') {//评测失败 + EasyLoading.showToast('评测失败'); + return; } }); }); @@ -96,7 +117,8 @@ class TopicPictureBloc extends Bloc { void _pageControllerChange(CurrentPageIndexChangeEvent event,Emitter emitter) async { _currentPage = event.pageIndex; final topics = _entity?.topics?[_currentPage]; - if (topics?.type == 1 || topics?.type == 2) { + if (topics?.type == 1 || topics?.type == 2 || topics?.type == 5) { + audioPlayer.stop(); if (topics?.audioUrl != null) { final urlStr = topics?.audioUrl??''; if (urlStr.isNotEmpty) { @@ -106,6 +128,7 @@ class TopicPictureBloc extends Bloc { } else { audioPlayer.stop(); } + _selectItem = -1; emitter(CurrentPageIndexState()); } @@ -119,7 +142,7 @@ class TopicPictureBloc extends Bloc { void _voiceXsTest(XSVoiceTestEvent event,Emitter emitter) async { EasyLoading.show(status: '录音中....'); methodChannel.invokeMethod( - 'startRecord', + 'starVoice', {'word':event.testWord,'type':event.type,'userId':event.userId.toString()} ); _isVoicing = true; diff --git a/lib/pages/practice/bloc/topic_picture_event.dart b/lib/pages/practice/bloc/topic_picture_event.dart index 0ab49b6..ec1650e 100644 --- a/lib/pages/practice/bloc/topic_picture_event.dart +++ b/lib/pages/practice/bloc/topic_picture_event.dart @@ -20,8 +20,8 @@ class XSVoiceResultEvent extends TopicPictureEvent { ///先声测试 class XSVoiceTestEvent extends TopicPictureEvent { final String testWord; - final int type; - final int userId; + final String type; + final String userId; XSVoiceTestEvent(this.testWord,this.type,this.userId); } diff --git a/lib/pages/practice/topic_picture_page.dart b/lib/pages/practice/topic_picture_page.dart index f5ad1ca..39910db 100644 --- a/lib/pages/practice/topic_picture_page.dart +++ b/lib/pages/practice/topic_picture_page.dart @@ -24,7 +24,7 @@ class TopicPicturePage extends StatelessWidget { { 'appKey':'a418', 'secretKey':'1a16f31f2611bf32fb7b3fc38f5b2c81', - 'userId':UserUtil.getUser()!.id + 'userId':UserUtil.getUser()!.id.toString() } )), child: _TopicPicturePage(), @@ -60,9 +60,8 @@ class _TopicPicturePage extends StatelessWidget { children: [ PracticeHeaderWidget( title: '${bloc.currentPage}/${bloc.entity?.topics?.length}', - onTap: (){ - bloc.add(XSVoiceTestEvent('Hello', 0,UserUtil.getUser()!.id)); - // Navigator.pop(context); + onTap: () { + Navigator.pop(context); }, ), Expanded( @@ -108,7 +107,7 @@ class _TopicPicturePage extends StatelessWidget { child: Column( children: [ Text( - 'What to do when the sentence question is very long and needs a line break', + topics?.word??'', softWrap: true, style: TextStyle( fontSize: 21.sp, @@ -120,10 +119,11 @@ class _TopicPicturePage extends StatelessWidget { height: 143.h, width: 143.w * (topics?.topicAnswerList?.length??0), child: ListView.builder( - itemCount: topics?.topicAnswerList?.length??0, scrollDirection: Axis.horizontal, + physics: const NeverScrollableScrollPhysics(), + itemCount: topics?.topicAnswerList?.length??0, itemBuilder: (context,index){ - return _decodeImageWidget(index); + return _decodeImageWidget(index,topics?.topicAnswerList?[index]); }), ), ], @@ -131,7 +131,7 @@ class _TopicPicturePage extends StatelessWidget { ); }); - Widget _decodeImageWidget(int index) => BlocBuilder( + Widget _decodeImageWidget(int index,CourseProcessTopicsTopicAnswerList? answerLis) => BlocBuilder( buildWhen: (_, s) => s is SelectItemChangeState, builder: (context,state){ final bloc = BlocProvider.of(context); @@ -155,9 +155,9 @@ class _TopicPicturePage extends StatelessWidget { width: 1.0, color: const Color(0xFF140C10) ), - image: const DecorationImage( + image: DecorationImage( fit: BoxFit.fitWidth, - image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714') + image: NetworkImage(answerLis?.picUrl??'') ) ), ), @@ -169,12 +169,11 @@ class _TopicPicturePage extends StatelessWidget { ///看题选字 Widget _pageViewWordItemWidget(CourseProcessTopics? topics) => BlocBuilder( builder: (context, state){ - final bloc = BlocProvider.of(context); return SafeArea( child: Column( children: [ Text( - 'What to do when the sentence question is very long and needs a line break', + topics?.word??'', softWrap: true, style: TextStyle( fontSize: 21.sp, @@ -186,10 +185,11 @@ class _TopicPicturePage extends StatelessWidget { height: 143.h, width: 143.w * (topics?.topicAnswerList?.length??0), child: ListView.builder( - itemCount: topics?.topicAnswerList?.length??0, scrollDirection: Axis.horizontal, + itemCount: topics?.topicAnswerList?.length??0, + physics: const NeverScrollableScrollPhysics(), itemBuilder: (context,index){ - return _decodeWordWidget(index); + return _decodeWordWidget(index,topics?.topicAnswerList?[index]); }), ), ], @@ -197,7 +197,7 @@ class _TopicPicturePage extends StatelessWidget { ); }); - Widget _decodeWordWidget(int index) => BlocBuilder( + Widget _decodeWordWidget(int index,CourseProcessTopicsTopicAnswerList? answerLis) => BlocBuilder( buildWhen: (_, s) => s is SelectItemChangeState, builder: (context,state){ final bloc = BlocProvider.of(context); @@ -224,7 +224,7 @@ class _TopicPicturePage extends StatelessWidget { child: Container( alignment: Alignment.center, child: Text( - 'yellow', + answerLis?.word??'', style: TextStyle( fontSize: 20.sp, color: const Color(0xFF333333) @@ -256,7 +256,6 @@ class _TopicPicturePage extends StatelessWidget { ///听音选图 Widget _pageViewVoicePictureItemWidget(CourseProcessTopics? topics) => BlocBuilder( builder: (context, state){ - final bloc = BlocProvider.of(context); return SafeArea( child: Column( children: [ @@ -266,7 +265,7 @@ class _TopicPicturePage extends StatelessWidget { Image.asset('voice'.assetPng,height: 33.h,width: 30.w,), 10.horizontalSpace, Text( - 'yellow', + topics?.word??'', style: TextStyle( fontSize: 20.sp, color: const Color(0xFF333333) @@ -280,9 +279,10 @@ class _TopicPicturePage extends StatelessWidget { width: 163.w * (topics?.topicAnswerList?.length??0), child: ListView.builder( scrollDirection: Axis.horizontal, + physics: const NeverScrollableScrollPhysics(), itemCount: topics?.topicAnswerList?.length??0, itemBuilder: (BuildContext context,int index){ - return _decodeVoiceImageWidget(1,topics?.topicAnswerList?[index]); + return _decodeVoiceImageWidget(index,topics?.topicAnswerList?[index]); }) , ) @@ -315,9 +315,9 @@ class _TopicPicturePage extends StatelessWidget { width: 1.0, color: const Color(0xFF140C10) ), - image: const DecorationImage( + image: DecorationImage( fit: BoxFit.fitWidth, - image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714') + image: NetworkImage(answerList?.picUrl??'') ) ), ), @@ -329,7 +329,6 @@ class _TopicPicturePage extends StatelessWidget { ///听音选字 Widget _pageViewVoiceWordItemWidget(CourseProcessTopics? topics) => BlocBuilder( builder: (context, state){ - final bloc = BlocProvider.of(context); return SafeArea( child: Column( children: [ @@ -339,8 +338,9 @@ class _TopicPicturePage extends StatelessWidget { width: 163.w * (topics?.topicAnswerList?.length??0), height: 143.h, child: ListView.builder( - itemCount: topics?.topicAnswerList?.length, scrollDirection: Axis.horizontal, + itemCount: topics?.topicAnswerList?.length, + physics: const NeverScrollableScrollPhysics(), itemBuilder: (BuildContext context,int index){ return _decodeVoiceWordImageWidget(index, topics!.topicAnswerList![index]); }), @@ -416,7 +416,7 @@ class _TopicPicturePage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ OwImageWidget( - name:'https://up.enterdesk.com/edpic_source/16/e7/0d/16e70d550daff77cbac31fae5e1651d4.jpg', + name:topics?.picUrl??'', height: 186.h, width: 186.w, ), @@ -424,10 +424,16 @@ class _TopicPicturePage extends StatelessWidget { Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image.asset( - 'voice'.assetPng, - height: 52.h, - width: 46.w, + Row( + children: [ + Image.asset( + 'voice'.assetPng, + height: 52.h, + width: 46.w, + ), + 10.horizontalSpace, + Text(topics?.word??'') + ], ), 70.verticalSpace, GestureDetector( @@ -435,7 +441,11 @@ class _TopicPicturePage extends StatelessWidget { if (bloc.isVoicing) { return; } - bloc.add(XSVoiceTestEvent('Hello', 0,UserUtil.getUser()!.id)); + if (topics?.type == 5) { + bloc.add(XSVoiceTestEvent(topics?.keyWord??'', '0',UserUtil.getUser()!.id.toString())); + } else { + bloc.add(XSVoiceTestEvent(topics?.word??'', '0',UserUtil.getUser()!.id.toString())); + } }, child: Image.asset( 'micro_phone'.assetPng, -- libgit2 0.22.2