gpt4 book ai didi

dart - flutter 中的答案颜色?

转载 作者:IT王子 更新时间:2023-10-29 07:11:50 25 4
gpt4 key购买 nike

我想确保在选择时,如果答案不正确则以红色突出显示,如果正确则以绿色突出显示。这在 Flutter 中如何实现?

    Column(
children: <Widget>[
new Text("Вопрос ${questionNumber + 1} из ${documentList.length}",
style: new TextStyle(
fontSize: 22.0,color: Colors.white
),),
new SizedBox(
height: 10.0,
),
Image.network(documentList[currentQuestionIndex]["image"]),
new SizedBox(
height: 10.0,
),
Text(documentList[currentQuestionIndex]["question"],style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold, fontSize: 16.0),textAlign: TextAlign.center,),
new SizedBox(
height: 20.0,
),
],

)];
List<String> options =
List<String>.from(documentList[currentQuestionIndex]["options"]);
for (int i = 0; i < options.length; i++) {
widgets.add(
ListTile(
title: Text("${(i + 1).toString()}. ${options[i]}.",style: TextStyle(color:Colors.white))
,onTap: () {questionNumber++;

最佳答案

试试这个,

取一个变量,例如isAnswerCorrect=false;

在选择答案时,根据结果设置标志。

setState(() {
isAnswerCorrect=true ||OR|| false;
});

现在您可以根据标志设置文本的颜色。

Text({ANSWER}, style: TextStyle(color: isAnswerCorrect ? Colors.green : Colors.red))

关于dart - flutter 中的答案颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55844690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com