简体   繁体   English

“字符串”类型不是“列表”类型的子类型<String> &#39; 在类型转换中?

[英]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']同时是StringList<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.

相关问题 “字符串”类型不是“列表”类型的子类型<string> '</string> - Type 'String' is not a subtype of type 'List<String>' Flutter。类型“Null”不是类型转换中类型“String”的子类型 - Flutter. type 'Null' is not a subtype of type 'String' in type cast “String”类型不是“FontStyle”类型的子类型 - type 'String' is not a subtype of type 'FontStyle' “时间戳”类型不是“字符串”类型的子类型 - type 'Timestamp' is not a subtype of type 'String' 未处理的异常:“String”类型不是“List”类型的子类型<String> &#39;的&#39;价值&#39; - Unhandled Exception: type 'String' is not a subtype of type 'List<String>' of 'value' Flutter 中的错误:“字符串”类型不是“地图”类型的子类型<string, dynamic> ? 在类型转换中</string,> - Error in Flutter: type 'string' is not a subtype of type 'map<string, dynamic>?' in type cast 输入'未来<dynamic>不是“字符串”类型的子类型</dynamic> - type 'Future<dynamic> is not subtype of type 'String' “int”类型不是“String”类型的子类型? 在 TextFormField 中 - type 'int' is not a subtype of type 'String?' in TextFormField &#39;String&#39; 类型不是 &#39;index&#39; Flutter 的 &#39;int&#39; 类型的子类型 - type 'String' is not a subtype of type 'int' of 'index' Flutter “String”类型不是 Flutter 中“Item”类型的子类型 - type 'String' is not a subtype of type 'Item' in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM