Commit 32b3acf4b6dd03ac92d0735cba372dfada1e4cac
1 parent
45c862fd
feat:选择题作答完毕颜色参考hkc
Showing
1 changed file
with
40 additions
and
20 deletions
lib/pages/practice/topic_picture_page.dart
... | ... | @@ -164,19 +164,22 @@ class _TopicPicturePage extends StatelessWidget { |
164 | 164 | buildWhen: (_, s) => s is SelectItemChangeState, |
165 | 165 | builder: (context, state) { |
166 | 166 | final bloc = BlocProvider.of<TopicPictureBloc>(context); |
167 | - final shouldShake = (bloc.selectItem == index && | |
168 | - bloc.checkAnswerRight(index) == false); | |
167 | + final isAnswerOption = bloc.selectItem == index; | |
168 | + final answerCorrect = isAnswerOption && | |
169 | + bloc.checkAnswerRight(index) == true; | |
170 | + final answerIncorrect = isAnswerOption && | |
171 | + bloc.checkAnswerRight(index) == false; | |
169 | 172 | return Container( |
170 | 173 | padding: EdgeInsets.symmetric(horizontal: 10.w), |
171 | 174 | child: GestureDetector( |
172 | 175 | onTap: () => bloc.add(SelectItemEvent(index)), |
173 | 176 | child: ShakeWidget( |
174 | - shouldShake: shouldShake, | |
177 | + shouldShake: answerIncorrect, | |
175 | 178 | child: Container( |
176 | 179 | padding: const EdgeInsets.all(4.5), |
177 | 180 | decoration: BoxDecoration( |
178 | - color: bloc.selectItem == index | |
179 | - ? const Color(0xFF00B6F1) | |
181 | + color: isAnswerOption | |
182 | + ? getResultColor(answerCorrect) | |
180 | 183 | : Colors.white, |
181 | 184 | borderRadius: BorderRadius.circular(15), |
182 | 185 | ), |
... | ... | @@ -233,14 +236,17 @@ class _TopicPicturePage extends StatelessWidget { |
233 | 236 | buildWhen: (_, s) => s is SelectItemChangeState, |
234 | 237 | builder: (context, state) { |
235 | 238 | final bloc = BlocProvider.of<TopicPictureBloc>(context); |
236 | - final shouldShake = (bloc.selectItem == index && | |
237 | - bloc.checkAnswerRight(index) == false); | |
239 | + final isAnswerOption = bloc.selectItem == index; | |
240 | + final answerCorrect = isAnswerOption && | |
241 | + bloc.checkAnswerRight(index) == true; | |
242 | + final answerIncorrect = isAnswerOption && | |
243 | + bloc.checkAnswerRight(index) == false; | |
238 | 244 | return Container( |
239 | 245 | padding: EdgeInsets.symmetric(horizontal: 10.w), |
240 | 246 | child: GestureDetector( |
241 | 247 | onTap: () => bloc.add(SelectItemEvent(index)), |
242 | 248 | child: ShakeWidget( |
243 | - shouldShake: shouldShake, | |
249 | + shouldShake: answerIncorrect, | |
244 | 250 | child: Container( |
245 | 251 | width: 143.w, |
246 | 252 | height: 143.h, |
... | ... | @@ -268,8 +274,8 @@ class _TopicPicturePage extends StatelessWidget { |
268 | 274 | height: 30.h, |
269 | 275 | width: double.infinity, |
270 | 276 | decoration: BoxDecoration( |
271 | - color: bloc.selectItem == index | |
272 | - ? const Color(0xFF00B6F1) | |
277 | + color: isAnswerOption | |
278 | + ? getResultColor(answerCorrect) | |
273 | 279 | : Colors.white, |
274 | 280 | borderRadius: BorderRadius.circular(15.r), |
275 | 281 | border: Border.all( |
... | ... | @@ -339,10 +345,13 @@ class _TopicPicturePage extends StatelessWidget { |
339 | 345 | buildWhen: (_, s) => s is SelectItemChangeState, |
340 | 346 | builder: (context, state) { |
341 | 347 | final bloc = BlocProvider.of<TopicPictureBloc>(context); |
342 | - final shouldShake = (bloc.selectItem == index && | |
343 | - bloc.checkAnswerRight(index) == false); | |
348 | + final isAnswerOption = bloc.selectItem == index; | |
349 | + final answerCorrect = isAnswerOption && | |
350 | + bloc.checkAnswerRight(index) == true; | |
351 | + final answerIncorrect = isAnswerOption && | |
352 | + bloc.checkAnswerRight(index) == false; | |
344 | 353 | return ShakeWidget( |
345 | - shouldShake: shouldShake, | |
354 | + shouldShake: answerIncorrect, | |
346 | 355 | child: Container( |
347 | 356 | padding: EdgeInsets.symmetric(horizontal: 20.w), |
348 | 357 | child: GestureDetector( |
... | ... | @@ -350,8 +359,8 @@ class _TopicPicturePage extends StatelessWidget { |
350 | 359 | child: Container( |
351 | 360 | padding: const EdgeInsets.all(4.5), |
352 | 361 | decoration: BoxDecoration( |
353 | - color: bloc.selectItem == index | |
354 | - ? const Color(0xFF00B6F1) | |
362 | + color: isAnswerOption | |
363 | + ? getResultColor(answerCorrect) | |
355 | 364 | : Colors.white, |
356 | 365 | borderRadius: BorderRadius.circular(15), |
357 | 366 | ), |
... | ... | @@ -413,12 +422,15 @@ class _TopicPicturePage extends StatelessWidget { |
413 | 422 | buildWhen: (_, s) => s is SelectItemChangeState, |
414 | 423 | builder: (context, state) { |
415 | 424 | final bloc = BlocProvider.of<TopicPictureBloc>(context); |
416 | - final shouldShake = (bloc.selectItem == index && | |
417 | - bloc.checkAnswerRight(index) == false); | |
425 | + final isAnswerOption = bloc.selectItem == index; | |
426 | + final answerCorrect = isAnswerOption && | |
427 | + bloc.checkAnswerRight(index) == true; | |
428 | + final answerIncorrect = isAnswerOption && | |
429 | + bloc.checkAnswerRight(index) == false; | |
418 | 430 | return GestureDetector( |
419 | 431 | onTap: () => bloc.add(SelectItemEvent(index)), |
420 | 432 | child: ShakeWidget( |
421 | - shouldShake: shouldShake, | |
433 | + shouldShake: answerIncorrect, | |
422 | 434 | child: Container( |
423 | 435 | width: 163.w, |
424 | 436 | height: 143.h, |
... | ... | @@ -450,8 +462,8 @@ class _TopicPicturePage extends StatelessWidget { |
450 | 462 | height: 30.h, |
451 | 463 | width: double.infinity, |
452 | 464 | decoration: BoxDecoration( |
453 | - color: bloc.selectItem == index | |
454 | - ? const Color(0xFF00B6F1) | |
465 | + color: isAnswerOption | |
466 | + ? getResultColor(answerCorrect) | |
455 | 467 | : Colors.white, |
456 | 468 | borderRadius: BorderRadius.circular(15.r), |
457 | 469 | border: Border.all( |
... | ... | @@ -548,4 +560,12 @@ class _TopicPicturePage extends StatelessWidget { |
548 | 560 | ], |
549 | 561 | ); |
550 | 562 | }); |
563 | + | |
564 | + Color getResultColor(bool correct) { | |
565 | + if (correct) { | |
566 | + return const Color(0xFF19D717); | |
567 | + } else { | |
568 | + return const Color(0xFFFF463C); | |
569 | + } | |
570 | + } | |
551 | 571 | } | ... | ... |