声明为:
List<String> _questionText = new List(creatingQuiz.totalQuestionsCount);
执行此:
TextFormField(
validator: (value) {
if (value.isEmpty) {
return 'Cannot be empty';
} else {
_questionText[qCount] = value;
return null;
}
},
decoration:
InputDecoration(labelText: "Question number $count"),
),
列表类型为字符串,值也为字符串类型。 仍然出现此类型错误:
type 'String' is not a subtype of type 'List<String>' of 'function result'
这是堆栈跟踪
When the exception was thrown, this was the stack
#0 _questionText (package:myshipapp/QuizApp/addQuestions.dart)
#1 _MyHomePageState.question.<anonymous closure>
package:myshipapp/QuizApp/addQuestions.dart:94
#2 FormFieldState._validate
package:flutter/…/widgets/form.dart:392
#3 FormFieldState.validate.<anonymous closure>
package:flutter/…/widgets/form.dart:385
#4 State.setState
package:flutter/…/widgets/framework.dart:1233
答案 0 :(得分:0)
List<String> _questionText = new List<String>(creatingQuiz.totalQuestionsCount);
我的声明不正确。谢谢大家。