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,19 +164,22 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 164 | buildWhen: (_, s) => s is SelectItemChangeState, | 164 | buildWhen: (_, s) => s is SelectItemChangeState, |
| 165 | builder: (context, state) { | 165 | builder: (context, state) { |
| 166 | final bloc = BlocProvider.of<TopicPictureBloc>(context); | 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 | return Container( | 172 | return Container( |
| 170 | padding: EdgeInsets.symmetric(horizontal: 10.w), | 173 | padding: EdgeInsets.symmetric(horizontal: 10.w), |
| 171 | child: GestureDetector( | 174 | child: GestureDetector( |
| 172 | onTap: () => bloc.add(SelectItemEvent(index)), | 175 | onTap: () => bloc.add(SelectItemEvent(index)), |
| 173 | child: ShakeWidget( | 176 | child: ShakeWidget( |
| 174 | - shouldShake: shouldShake, | 177 | + shouldShake: answerIncorrect, |
| 175 | child: Container( | 178 | child: Container( |
| 176 | padding: const EdgeInsets.all(4.5), | 179 | padding: const EdgeInsets.all(4.5), |
| 177 | decoration: BoxDecoration( | 180 | decoration: BoxDecoration( |
| 178 | - color: bloc.selectItem == index | ||
| 179 | - ? const Color(0xFF00B6F1) | 181 | + color: isAnswerOption |
| 182 | + ? getResultColor(answerCorrect) | ||
| 180 | : Colors.white, | 183 | : Colors.white, |
| 181 | borderRadius: BorderRadius.circular(15), | 184 | borderRadius: BorderRadius.circular(15), |
| 182 | ), | 185 | ), |
| @@ -233,14 +236,17 @@ class _TopicPicturePage extends StatelessWidget { | @@ -233,14 +236,17 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 233 | buildWhen: (_, s) => s is SelectItemChangeState, | 236 | buildWhen: (_, s) => s is SelectItemChangeState, |
| 234 | builder: (context, state) { | 237 | builder: (context, state) { |
| 235 | final bloc = BlocProvider.of<TopicPictureBloc>(context); | 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 | return Container( | 244 | return Container( |
| 239 | padding: EdgeInsets.symmetric(horizontal: 10.w), | 245 | padding: EdgeInsets.symmetric(horizontal: 10.w), |
| 240 | child: GestureDetector( | 246 | child: GestureDetector( |
| 241 | onTap: () => bloc.add(SelectItemEvent(index)), | 247 | onTap: () => bloc.add(SelectItemEvent(index)), |
| 242 | child: ShakeWidget( | 248 | child: ShakeWidget( |
| 243 | - shouldShake: shouldShake, | 249 | + shouldShake: answerIncorrect, |
| 244 | child: Container( | 250 | child: Container( |
| 245 | width: 143.w, | 251 | width: 143.w, |
| 246 | height: 143.h, | 252 | height: 143.h, |
| @@ -268,8 +274,8 @@ class _TopicPicturePage extends StatelessWidget { | @@ -268,8 +274,8 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 268 | height: 30.h, | 274 | height: 30.h, |
| 269 | width: double.infinity, | 275 | width: double.infinity, |
| 270 | decoration: BoxDecoration( | 276 | decoration: BoxDecoration( |
| 271 | - color: bloc.selectItem == index | ||
| 272 | - ? const Color(0xFF00B6F1) | 277 | + color: isAnswerOption |
| 278 | + ? getResultColor(answerCorrect) | ||
| 273 | : Colors.white, | 279 | : Colors.white, |
| 274 | borderRadius: BorderRadius.circular(15.r), | 280 | borderRadius: BorderRadius.circular(15.r), |
| 275 | border: Border.all( | 281 | border: Border.all( |
| @@ -339,10 +345,13 @@ class _TopicPicturePage extends StatelessWidget { | @@ -339,10 +345,13 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 339 | buildWhen: (_, s) => s is SelectItemChangeState, | 345 | buildWhen: (_, s) => s is SelectItemChangeState, |
| 340 | builder: (context, state) { | 346 | builder: (context, state) { |
| 341 | final bloc = BlocProvider.of<TopicPictureBloc>(context); | 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 | return ShakeWidget( | 353 | return ShakeWidget( |
| 345 | - shouldShake: shouldShake, | 354 | + shouldShake: answerIncorrect, |
| 346 | child: Container( | 355 | child: Container( |
| 347 | padding: EdgeInsets.symmetric(horizontal: 20.w), | 356 | padding: EdgeInsets.symmetric(horizontal: 20.w), |
| 348 | child: GestureDetector( | 357 | child: GestureDetector( |
| @@ -350,8 +359,8 @@ class _TopicPicturePage extends StatelessWidget { | @@ -350,8 +359,8 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 350 | child: Container( | 359 | child: Container( |
| 351 | padding: const EdgeInsets.all(4.5), | 360 | padding: const EdgeInsets.all(4.5), |
| 352 | decoration: BoxDecoration( | 361 | decoration: BoxDecoration( |
| 353 | - color: bloc.selectItem == index | ||
| 354 | - ? const Color(0xFF00B6F1) | 362 | + color: isAnswerOption |
| 363 | + ? getResultColor(answerCorrect) | ||
| 355 | : Colors.white, | 364 | : Colors.white, |
| 356 | borderRadius: BorderRadius.circular(15), | 365 | borderRadius: BorderRadius.circular(15), |
| 357 | ), | 366 | ), |
| @@ -413,12 +422,15 @@ class _TopicPicturePage extends StatelessWidget { | @@ -413,12 +422,15 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 413 | buildWhen: (_, s) => s is SelectItemChangeState, | 422 | buildWhen: (_, s) => s is SelectItemChangeState, |
| 414 | builder: (context, state) { | 423 | builder: (context, state) { |
| 415 | final bloc = BlocProvider.of<TopicPictureBloc>(context); | 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 | return GestureDetector( | 430 | return GestureDetector( |
| 419 | onTap: () => bloc.add(SelectItemEvent(index)), | 431 | onTap: () => bloc.add(SelectItemEvent(index)), |
| 420 | child: ShakeWidget( | 432 | child: ShakeWidget( |
| 421 | - shouldShake: shouldShake, | 433 | + shouldShake: answerIncorrect, |
| 422 | child: Container( | 434 | child: Container( |
| 423 | width: 163.w, | 435 | width: 163.w, |
| 424 | height: 143.h, | 436 | height: 143.h, |
| @@ -450,8 +462,8 @@ class _TopicPicturePage extends StatelessWidget { | @@ -450,8 +462,8 @@ class _TopicPicturePage extends StatelessWidget { | ||
| 450 | height: 30.h, | 462 | height: 30.h, |
| 451 | width: double.infinity, | 463 | width: double.infinity, |
| 452 | decoration: BoxDecoration( | 464 | decoration: BoxDecoration( |
| 453 | - color: bloc.selectItem == index | ||
| 454 | - ? const Color(0xFF00B6F1) | 465 | + color: isAnswerOption |
| 466 | + ? getResultColor(answerCorrect) | ||
| 455 | : Colors.white, | 467 | : Colors.white, |
| 456 | borderRadius: BorderRadius.circular(15.r), | 468 | borderRadius: BorderRadius.circular(15.r), |
| 457 | border: Border.all( | 469 | border: Border.all( |
| @@ -548,4 +560,12 @@ class _TopicPicturePage extends StatelessWidget { | @@ -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 | } |