在颤动中回答颜色?

问题描述 投票:0回答:1

我想确保在选择时,如果不正确,答案将以红色突出显示,如果正确,则以绿色突出显示。如何在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++;
dart flutter
1个回答
2
投票

试试这个,

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

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

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

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

Text({ANSWER}, style: TextStyle(color: isAnswerCorrect ? Colors.green : Colors.red))
© www.soinside.com 2019 - 2024. All rights reserved.