我试图在颤动中进行多项选择测验,但我在按钮和文本视图中分配字符串时遇到困难

时间:2018-06-07 01:48:19

标签: dart flutter

正如您在listAnswers[1]所看到的那样,我确实尝试在文本视图中指定字符串'white',但它崩溃了我的程序,任何人都知道为什么,我有类问题包含字符串问题,列表使用答案和一个正确答案进行评估的字符串,以及一个用于构建测验的测验类。

Questions currentQuestion;

Quiz quiz = new Quiz([
new Questions("Color of the snow is ", ["yellow", "white","grey"],'white']);
 String questionText;
 int questionNumber;
 String isCorrect;
 List<String> listAnswers;

 @override
void initState() {
super.initState();
currentQuestion = quiz.nextQuestion;
questionText = currentQuestion.question;
questionNumber = quiz.questionNumber;
listAnswers = quiz.answers;
isCorrect = quiz.correctAnswer;
}

@override
Widget build(BuildContext context) {
return new Scaffold(
  appBar: new AppBar(
    title: new Text(widget.title),
  ),
  body: new InkWell(
    child: Center(
      child: new Column(
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: new Text(
              questionText,
              maxLines: questionNumber,
              style: new TextStyle(fontSize: 20.0),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: new Text(
              listAnswers[1],
              style: new TextStyle(fontSize: 20.0),
            ),
          ),
        ],
      ),
    ),
   ),
  );
 }
}

0 个答案:

没有答案