[英]type 'String' is not a subtype of type 'List<String>' in type cast?
How can I fix that?我该如何解决? I can't run the code because there is an error at String我无法运行代码,因为 String 有错误
Text(
questions[_questionsIndex]['questionText'] as String,
style: TextStyle(color: Colors.orange, fontSize: 30),
),
...(questions[_questionsIndex]['questionText'] as List<String>).map((answer) {
return Answer(_answerQuestions, answer);
}).toList()
The problem is this:问题是这样的:
questions[_questionsIndex]['questionText'] as String
questions[_questionsIndex]['questionText'] as List<String>
How can questions[_questionsIndex]['questionText']
be a String
and a List<String>
at the same time? questions[_questionsIndex]['questionText']
同时是String
和List<String>
?
I can't know for sure since you didn't show whats inside of questions
variable and we don't know what you want to do but you probably want to do something like this:我不能确定,因为你没有显示questions
变量里面的内容,我们不知道你想做什么,但你可能想做这样的事情:
...(questions as List<Map<String, dynamic>>).map((question) {
return Answer(_answerQuestions, question['questionText']);
}).toList()
I decided to do an online course at Udemy (flutter) and this code was shown, to load the questions & answers by a quiz:我决定在 Udemy (flutter) 上做一门在线课程,并显示了此代码,以通过测验加载问题和答案:
Question(
questions[_questionsIndex]['questionText'],
),
...(questions[_questionsIndex]['questionText'] as List<String>).map((answer) {
return Answer(_answerQuestions, answer);
}).toList()
but actually it doesn't work.但实际上它不起作用。 I tried to put 'as String' to the first Line, but the Emulator does show an error.我试图将“作为字符串”放在第一行,但模拟器确实显示错误。 So I tried your Version but it doesn't helped me所以我尝试了你的版本,但它没有帮助我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.