From 32b3acf4b6dd03ac92d0735cba372dfada1e4cac Mon Sep 17 00:00:00 2001 From: wuqifeng <540416539@qq.com> Date: Mon, 29 Jul 2024 14:34:10 +0800 Subject: [PATCH] feat:选择题作答完毕颜色参考hkc --- lib/pages/practice/topic_picture_page.dart | 60 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/lib/pages/practice/topic_picture_page.dart b/lib/pages/practice/topic_picture_page.dart index 6873c6a..5d1c554 100644 --- a/lib/pages/practice/topic_picture_page.dart +++ b/lib/pages/practice/topic_picture_page.dart @@ -164,19 +164,22 @@ class _TopicPicturePage extends StatelessWidget { buildWhen: (_, s) => s is SelectItemChangeState, builder: (context, state) { final bloc = BlocProvider.of(context); - final shouldShake = (bloc.selectItem == index && - bloc.checkAnswerRight(index) == false); + final isAnswerOption = bloc.selectItem == index; + final answerCorrect = isAnswerOption && + bloc.checkAnswerRight(index) == true; + final answerIncorrect = isAnswerOption && + bloc.checkAnswerRight(index) == false; return Container( padding: EdgeInsets.symmetric(horizontal: 10.w), child: GestureDetector( onTap: () => bloc.add(SelectItemEvent(index)), child: ShakeWidget( - shouldShake: shouldShake, + shouldShake: answerIncorrect, child: Container( padding: const EdgeInsets.all(4.5), decoration: BoxDecoration( - color: bloc.selectItem == index - ? const Color(0xFF00B6F1) + color: isAnswerOption + ? getResultColor(answerCorrect) : Colors.white, borderRadius: BorderRadius.circular(15), ), @@ -233,14 +236,17 @@ class _TopicPicturePage extends StatelessWidget { buildWhen: (_, s) => s is SelectItemChangeState, builder: (context, state) { final bloc = BlocProvider.of(context); - final shouldShake = (bloc.selectItem == index && - bloc.checkAnswerRight(index) == false); + final isAnswerOption = bloc.selectItem == index; + final answerCorrect = isAnswerOption && + bloc.checkAnswerRight(index) == true; + final answerIncorrect = isAnswerOption && + bloc.checkAnswerRight(index) == false; return Container( padding: EdgeInsets.symmetric(horizontal: 10.w), child: GestureDetector( onTap: () => bloc.add(SelectItemEvent(index)), child: ShakeWidget( - shouldShake: shouldShake, + shouldShake: answerIncorrect, child: Container( width: 143.w, height: 143.h, @@ -268,8 +274,8 @@ class _TopicPicturePage extends StatelessWidget { height: 30.h, width: double.infinity, decoration: BoxDecoration( - color: bloc.selectItem == index - ? const Color(0xFF00B6F1) + color: isAnswerOption + ? getResultColor(answerCorrect) : Colors.white, borderRadius: BorderRadius.circular(15.r), border: Border.all( @@ -339,10 +345,13 @@ class _TopicPicturePage extends StatelessWidget { buildWhen: (_, s) => s is SelectItemChangeState, builder: (context, state) { final bloc = BlocProvider.of(context); - final shouldShake = (bloc.selectItem == index && - bloc.checkAnswerRight(index) == false); + final isAnswerOption = bloc.selectItem == index; + final answerCorrect = isAnswerOption && + bloc.checkAnswerRight(index) == true; + final answerIncorrect = isAnswerOption && + bloc.checkAnswerRight(index) == false; return ShakeWidget( - shouldShake: shouldShake, + shouldShake: answerIncorrect, child: Container( padding: EdgeInsets.symmetric(horizontal: 20.w), child: GestureDetector( @@ -350,8 +359,8 @@ class _TopicPicturePage extends StatelessWidget { child: Container( padding: const EdgeInsets.all(4.5), decoration: BoxDecoration( - color: bloc.selectItem == index - ? const Color(0xFF00B6F1) + color: isAnswerOption + ? getResultColor(answerCorrect) : Colors.white, borderRadius: BorderRadius.circular(15), ), @@ -413,12 +422,15 @@ class _TopicPicturePage extends StatelessWidget { buildWhen: (_, s) => s is SelectItemChangeState, builder: (context, state) { final bloc = BlocProvider.of(context); - final shouldShake = (bloc.selectItem == index && - bloc.checkAnswerRight(index) == false); + final isAnswerOption = bloc.selectItem == index; + final answerCorrect = isAnswerOption && + bloc.checkAnswerRight(index) == true; + final answerIncorrect = isAnswerOption && + bloc.checkAnswerRight(index) == false; return GestureDetector( onTap: () => bloc.add(SelectItemEvent(index)), child: ShakeWidget( - shouldShake: shouldShake, + shouldShake: answerIncorrect, child: Container( width: 163.w, height: 143.h, @@ -450,8 +462,8 @@ class _TopicPicturePage extends StatelessWidget { height: 30.h, width: double.infinity, decoration: BoxDecoration( - color: bloc.selectItem == index - ? const Color(0xFF00B6F1) + color: isAnswerOption + ? getResultColor(answerCorrect) : Colors.white, borderRadius: BorderRadius.circular(15.r), border: Border.all( @@ -548,4 +560,12 @@ class _TopicPicturePage extends StatelessWidget { ], ); }); + + Color getResultColor(bool correct) { + if (correct) { + return const Color(0xFF19D717); + } else { + return const Color(0xFFFF463C); + } + } } -- libgit2 0.22.2