Commit b90a1518bad80adb31be3f058759242e5f0d6021

Authored by liangchengyou
1 parent e3c2820c

feat:练习接口逻辑完成

ios/Runner/XSMessageMehtodChannel.swift
... ... @@ -21,16 +21,18 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
21 21  
22 22 //配置评测信息
23 23 func setEvaluateConfig(dict:Dictionary<String, Any>) {
24   - let appKey = dict["appKey"] as? String
25   - let secretKey = dict["secretKey"] as? String
26   - let userId = dict.keys.contains("userId") ? dict["userId"] as! String:""
27   - let frontTime = dict["frontTime"] as? TimeInterval
28   - let backTime = dict["frontTime"] as? TimeInterval
  24 + let appKey = dict["appKey"] as? String ?? ""
  25 + let secretKey = dict["secretKey"] as? String ?? ""
  26 + let userId = dict["userId"] as? String ?? "guest"
  27 + let frontTime = dict["frontTime"] as? String ?? "3"
  28 + let backTime = dict["frontTime"] as? String ?? "3"
29 29 let config = SSOralEvaluatingManagerConfig.init()
  30 + config.vad = true
  31 + config.isOutputLog = false
30 32 config.appKey = appKey //"a418"
31 33 config.secretKey = secretKey //"1a16f31f2611bf32fb7b3fc38f5b2c81"'
32   - config.frontTime = frontTime ?? 3
33   - config.backTime = backTime ?? 3
  34 + config.frontTime = Double(frontTime)!
  35 + config.backTime = Double(backTime)!
34 36 SSOralEvaluatingManager.register(config)
35 37 SSOralEvaluatingManager.share().register(.line, userId: userId)
36 38 SSOralEvaluatingManager.share().delegate = self
... ... @@ -38,12 +40,12 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
38 40  
39 41 //开始评测
40 42 func evaluateVioce(dict:Dictionary<String, Any>) {
41   - let text = dict["word"] as! String
42   - let type = dict["type"] as! Int
43   - let userId = dict["userId"] as! String
  43 + let text = dict["word"] as? String ?? ""
  44 + let type = dict["type"] as? String ?? "0"
  45 + let userId = dict["userId"] as? String ?? "guest"
44 46 let config = SSOralEvaluatingConfig()
45 47 config.oralContent = text
46   - if (type == 0) {
  48 + if (type == "0") {
47 49 config.oralType = .word
48 50 } else {
49 51 config.oralType = .sentence
... ... @@ -79,7 +81,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
79 81 */
80 82 func oralEvaluatingDidStart() {
81 83 print("评测开始")
82   - messageChannel!.invokeMethod("voiceStart", arguments: nil)
  84 +// messageChannel!.invokeMethod("voiceStart", arguments: nil)
83 85 }
84 86  
85 87 /**
... ... @@ -87,7 +89,7 @@ class XSMessageMehtodChannel: NSObject,SSOralEvaluatingManagerDelegate {
87 89 */
88 90 func oralEvaluatingDidStop() {
89 91 print("评测结束")
90   - messageChannel!.invokeMethod("voiceEnd",arguments: nil)
  92 +// messageChannel!.invokeMethod("voiceEnd",arguments: nil)
91 93 }
92 94  
93 95 /**
... ...
lib/pages/home/home_page.dart
... ... @@ -37,7 +37,8 @@ class _HomePageView extends StatelessWidget {
37 37 } else if (type == HeaderActionType.shop) {
38 38 Navigator.of(AppRouter.context).pushNamed(AppRouteName.shop);
39 39 } else if (type == HeaderActionType.user) {
40   - Navigator.of(AppRouter.context).pushNamed(AppRouteName.user);
  40 + // Navigator.of(AppRouter.context).pushNamed(AppRouteName.user);
  41 + Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic);
41 42 } else {
42 43 // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic);
43 44 }
... ...
lib/pages/practice/bloc/topic_picture_bloc.dart
... ... @@ -50,17 +50,38 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
50 50 //音频播放器
51 51 audioPlayer = AudioPlayer();
52 52 audioPlayer.onPlayerStateChanged.listen((event) {
53   - if (event == PlayerState.stopped) {
  53 + if (event == PlayerState.completed) {
  54 + if (kDebugMode) {
  55 + print('播放完成');
54 56  
55   - }
  57 + }}
56 58 });
57 59  
58 60  
59 61 methodChannel = const MethodChannel('wow_english/sing_sound_method_channely');
60   - methodChannel.invokeMethod('initVoiceSdk',{});
61 62 methodChannel.setMethodCallHandler((call) async {
62   - if (call.method == 'voiceResult') {//评测结
  63 + if (call.method == 'voiceResult') {//评测结
63 64 add(XSVoiceResultEvent(call.arguments));
  65 + return;
  66 + }
  67 +
  68 + if (call.method == 'voiceStart') {//评测开始
  69 + if (kDebugMode) {
  70 + print('评测开始');
  71 + }
  72 + return;
  73 + }
  74 +
  75 + if (call.method == 'voiceEnd') {//评测结束
  76 + if (kDebugMode) {
  77 + print('评测结束');
  78 + }
  79 + return;
  80 + }
  81 +
  82 + if (call.method == 'voiceFail') {//评测失败
  83 + EasyLoading.showToast('评测失败');
  84 + return;
64 85 }
65 86 });
66 87 });
... ... @@ -96,7 +117,8 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
96 117 void _pageControllerChange(CurrentPageIndexChangeEvent event,Emitter<TopicPictureState> emitter) async {
97 118 _currentPage = event.pageIndex;
98 119 final topics = _entity?.topics?[_currentPage];
99   - if (topics?.type == 1 || topics?.type == 2) {
  120 + if (topics?.type == 1 || topics?.type == 2 || topics?.type == 5) {
  121 + audioPlayer.stop();
100 122 if (topics?.audioUrl != null) {
101 123 final urlStr = topics?.audioUrl??'';
102 124 if (urlStr.isNotEmpty) {
... ... @@ -106,6 +128,7 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
106 128 } else {
107 129 audioPlayer.stop();
108 130 }
  131 + _selectItem = -1;
109 132 emitter(CurrentPageIndexState());
110 133 }
111 134  
... ... @@ -119,7 +142,7 @@ class TopicPictureBloc extends Bloc&lt;TopicPictureEvent, TopicPictureState&gt; {
119 142 void _voiceXsTest(XSVoiceTestEvent event,Emitter<TopicPictureState> emitter) async {
120 143 EasyLoading.show(status: '录音中....');
121 144 methodChannel.invokeMethod(
122   - 'startRecord',
  145 + 'starVoice',
123 146 {'word':event.testWord,'type':event.type,'userId':event.userId.toString()}
124 147 );
125 148 _isVoicing = true;
... ...
lib/pages/practice/bloc/topic_picture_event.dart
... ... @@ -20,8 +20,8 @@ class XSVoiceResultEvent extends TopicPictureEvent {
20 20 ///先声测试
21 21 class XSVoiceTestEvent extends TopicPictureEvent {
22 22 final String testWord;
23   - final int type;
24   - final int userId;
  23 + final String type;
  24 + final String userId;
25 25 XSVoiceTestEvent(this.testWord,this.type,this.userId);
26 26 }
27 27  
... ...
lib/pages/practice/topic_picture_page.dart
... ... @@ -24,7 +24,7 @@ class TopicPicturePage extends StatelessWidget {
24 24 {
25 25 'appKey':'a418',
26 26 'secretKey':'1a16f31f2611bf32fb7b3fc38f5b2c81',
27   - 'userId':UserUtil.getUser()!.id
  27 + 'userId':UserUtil.getUser()!.id.toString()
28 28 }
29 29 )),
30 30 child: _TopicPicturePage(),
... ... @@ -60,9 +60,8 @@ class _TopicPicturePage extends StatelessWidget {
60 60 children: [
61 61 PracticeHeaderWidget(
62 62 title: '${bloc.currentPage}/${bloc.entity?.topics?.length}',
63   - onTap: (){
64   - bloc.add(XSVoiceTestEvent('Hello', 0,UserUtil.getUser()!.id));
65   - // Navigator.pop(context);
  63 + onTap: () {
  64 + Navigator.pop(context);
66 65 },
67 66 ),
68 67 Expanded(
... ... @@ -108,7 +107,7 @@ class _TopicPicturePage extends StatelessWidget {
108 107 child: Column(
109 108 children: [
110 109 Text(
111   - 'What to do when the sentence question is very long and needs a line break',
  110 + topics?.word??'',
112 111 softWrap: true,
113 112 style: TextStyle(
114 113 fontSize: 21.sp,
... ... @@ -120,10 +119,11 @@ class _TopicPicturePage extends StatelessWidget {
120 119 height: 143.h,
121 120 width: 143.w * (topics?.topicAnswerList?.length??0),
122 121 child: ListView.builder(
123   - itemCount: topics?.topicAnswerList?.length??0,
124 122 scrollDirection: Axis.horizontal,
  123 + physics: const NeverScrollableScrollPhysics(),
  124 + itemCount: topics?.topicAnswerList?.length??0,
125 125 itemBuilder: (context,index){
126   - return _decodeImageWidget(index);
  126 + return _decodeImageWidget(index,topics?.topicAnswerList?[index]);
127 127 }),
128 128 ),
129 129 ],
... ... @@ -131,7 +131,7 @@ class _TopicPicturePage extends StatelessWidget {
131 131 );
132 132 });
133 133  
134   - Widget _decodeImageWidget(int index) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
  134 + Widget _decodeImageWidget(int index,CourseProcessTopicsTopicAnswerList? answerLis) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
135 135 buildWhen: (_, s) => s is SelectItemChangeState,
136 136 builder: (context,state){
137 137 final bloc = BlocProvider.of<TopicPictureBloc>(context);
... ... @@ -155,9 +155,9 @@ class _TopicPicturePage extends StatelessWidget {
155 155 width: 1.0,
156 156 color: const Color(0xFF140C10)
157 157 ),
158   - image: const DecorationImage(
  158 + image: DecorationImage(
159 159 fit: BoxFit.fitWidth,
160   - image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714')
  160 + image: NetworkImage(answerLis?.picUrl??'')
161 161 )
162 162 ),
163 163 ),
... ... @@ -169,12 +169,11 @@ class _TopicPicturePage extends StatelessWidget {
169 169 ///看题选字
170 170 Widget _pageViewWordItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
171 171 builder: (context, state){
172   - final bloc = BlocProvider.of<TopicPictureBloc>(context);
173 172 return SafeArea(
174 173 child: Column(
175 174 children: [
176 175 Text(
177   - 'What to do when the sentence question is very long and needs a line break',
  176 + topics?.word??'',
178 177 softWrap: true,
179 178 style: TextStyle(
180 179 fontSize: 21.sp,
... ... @@ -186,10 +185,11 @@ class _TopicPicturePage extends StatelessWidget {
186 185 height: 143.h,
187 186 width: 143.w * (topics?.topicAnswerList?.length??0),
188 187 child: ListView.builder(
189   - itemCount: topics?.topicAnswerList?.length??0,
190 188 scrollDirection: Axis.horizontal,
  189 + itemCount: topics?.topicAnswerList?.length??0,
  190 + physics: const NeverScrollableScrollPhysics(),
191 191 itemBuilder: (context,index){
192   - return _decodeWordWidget(index);
  192 + return _decodeWordWidget(index,topics?.topicAnswerList?[index]);
193 193 }),
194 194 ),
195 195 ],
... ... @@ -197,7 +197,7 @@ class _TopicPicturePage extends StatelessWidget {
197 197 );
198 198 });
199 199  
200   - Widget _decodeWordWidget(int index) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
  200 + Widget _decodeWordWidget(int index,CourseProcessTopicsTopicAnswerList? answerLis) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
201 201 buildWhen: (_, s) => s is SelectItemChangeState,
202 202 builder: (context,state){
203 203 final bloc = BlocProvider.of<TopicPictureBloc>(context);
... ... @@ -224,7 +224,7 @@ class _TopicPicturePage extends StatelessWidget {
224 224 child: Container(
225 225 alignment: Alignment.center,
226 226 child: Text(
227   - 'yellow',
  227 + answerLis?.word??'',
228 228 style: TextStyle(
229 229 fontSize: 20.sp,
230 230 color: const Color(0xFF333333)
... ... @@ -256,7 +256,6 @@ class _TopicPicturePage extends StatelessWidget {
256 256 ///听音选图
257 257 Widget _pageViewVoicePictureItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
258 258 builder: (context, state){
259   - final bloc = BlocProvider.of<TopicPictureBloc>(context);
260 259 return SafeArea(
261 260 child: Column(
262 261 children: [
... ... @@ -266,7 +265,7 @@ class _TopicPicturePage extends StatelessWidget {
266 265 Image.asset('voice'.assetPng,height: 33.h,width: 30.w,),
267 266 10.horizontalSpace,
268 267 Text(
269   - 'yellow',
  268 + topics?.word??'',
270 269 style: TextStyle(
271 270 fontSize: 20.sp,
272 271 color: const Color(0xFF333333)
... ... @@ -280,9 +279,10 @@ class _TopicPicturePage extends StatelessWidget {
280 279 width: 163.w * (topics?.topicAnswerList?.length??0),
281 280 child: ListView.builder(
282 281 scrollDirection: Axis.horizontal,
  282 + physics: const NeverScrollableScrollPhysics(),
283 283 itemCount: topics?.topicAnswerList?.length??0,
284 284 itemBuilder: (BuildContext context,int index){
285   - return _decodeVoiceImageWidget(1,topics?.topicAnswerList?[index]);
  285 + return _decodeVoiceImageWidget(index,topics?.topicAnswerList?[index]);
286 286 })
287 287 ,
288 288 )
... ... @@ -315,9 +315,9 @@ class _TopicPicturePage extends StatelessWidget {
315 315 width: 1.0,
316 316 color: const Color(0xFF140C10)
317 317 ),
318   - image: const DecorationImage(
  318 + image: DecorationImage(
319 319 fit: BoxFit.fitWidth,
320   - image: NetworkImage('https://img1.baidu.com/it/u=3392591833,1640391553&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=714')
  320 + image: NetworkImage(answerList?.picUrl??'')
321 321 )
322 322 ),
323 323 ),
... ... @@ -329,7 +329,6 @@ class _TopicPicturePage extends StatelessWidget {
329 329 ///听音选字
330 330 Widget _pageViewVoiceWordItemWidget(CourseProcessTopics? topics) => BlocBuilder<TopicPictureBloc,TopicPictureState>(
331 331 builder: (context, state){
332   - final bloc = BlocProvider.of<TopicPictureBloc>(context);
333 332 return SafeArea(
334 333 child: Column(
335 334 children: [
... ... @@ -339,8 +338,9 @@ class _TopicPicturePage extends StatelessWidget {
339 338 width: 163.w * (topics?.topicAnswerList?.length??0),
340 339 height: 143.h,
341 340 child: ListView.builder(
342   - itemCount: topics?.topicAnswerList?.length,
343 341 scrollDirection: Axis.horizontal,
  342 + itemCount: topics?.topicAnswerList?.length,
  343 + physics: const NeverScrollableScrollPhysics(),
344 344 itemBuilder: (BuildContext context,int index){
345 345 return _decodeVoiceWordImageWidget(index, topics!.topicAnswerList![index]);
346 346 }),
... ... @@ -416,7 +416,7 @@ class _TopicPicturePage extends StatelessWidget {
416 416 mainAxisAlignment: MainAxisAlignment.center,
417 417 children: [
418 418 OwImageWidget(
419   - name:'https://up.enterdesk.com/edpic_source/16/e7/0d/16e70d550daff77cbac31fae5e1651d4.jpg',
  419 + name:topics?.picUrl??'',
420 420 height: 186.h,
421 421 width: 186.w,
422 422 ),
... ... @@ -424,10 +424,16 @@ class _TopicPicturePage extends StatelessWidget {
424 424 Column(
425 425 mainAxisAlignment: MainAxisAlignment.center,
426 426 children: [
427   - Image.asset(
428   - 'voice'.assetPng,
429   - height: 52.h,
430   - width: 46.w,
  427 + Row(
  428 + children: [
  429 + Image.asset(
  430 + 'voice'.assetPng,
  431 + height: 52.h,
  432 + width: 46.w,
  433 + ),
  434 + 10.horizontalSpace,
  435 + Text(topics?.word??'')
  436 + ],
431 437 ),
432 438 70.verticalSpace,
433 439 GestureDetector(
... ... @@ -435,7 +441,11 @@ class _TopicPicturePage extends StatelessWidget {
435 441 if (bloc.isVoicing) {
436 442 return;
437 443 }
438   - bloc.add(XSVoiceTestEvent('Hello', 0,UserUtil.getUser()!.id));
  444 + if (topics?.type == 5) {
  445 + bloc.add(XSVoiceTestEvent(topics?.keyWord??'', '0',UserUtil.getUser()!.id.toString()));
  446 + } else {
  447 + bloc.add(XSVoiceTestEvent(topics?.word??'', '0',UserUtil.getUser()!.id.toString()));
  448 + }
439 449 },
440 450 child: Image.asset(
441 451 'micro_phone'.assetPng,
... ...