简体   繁体   English

错误:没有为 class“对象?”定义方法“地图”

[英]Error: The method 'map' isn't defined for the class 'Object?'

var questions = [
  {
    'questionText' : 'What\'s your favorite colour? ',
    'answers' : [ 'Green', 'Red', 'Yellow', 'Black'],
  },
];
return MaterialApp(
  home: Scaffold(
    appBar: AppBar(
      title: Text('My second app'),
    ),
    body: Column(
      children: [
        Question(
            questions[_questionIndex]['questionText'] as String
        ),
        **questions[_questionIndex]['answers'].map((answer){
          return Answer('', answer);
          }),**

I tried to put "as String" but nothing worked, the compiler always returns the same error我试图把“作为字符串”,但没有任何效果,编译器总是返回相同的错误

You need to let dart know what questions[_questionIndex]['answers'] is, you can use as to do this:您需要让 dart 知道questions[_questionIndex]['answers']是什么,您可以使用as来执行此操作:

(questions[_questionIndex]['answers'] as List<String>).map((answer){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:未为类“Object?”定义方法“data” - Error: The method 'data' isn't defined for the class 'Object?' 错误:没有为 class 定义方法“flatbutton” - error: the method ´flatbutton´ isn´t defined for the class 没有为 class 定义该方法 - The method isn't defined for the class 错误:没有为 class 'Object' 定义 getter 'documents' - Error: The getter 'documents' isn't defined for the class 'Object' 方法 &#39;listen&#39; 没有为类 &#39;Function&#39; 定义? - The method 'listen' isn't defined for the class 'Function'? Flutter:未为类“ FirebaseAuth”定义方法“ signInWithGoogle” - Flutter:The method 'signInWithGoogle' isn't defined for the class 'FirebaseAuth' 未定义方法“MaterialPageRoute” - The method 'MaterialPageRoute' isn't defined 错误:没有为“完成者”类型定义方法“setMapStyle” - error: The method 'setMapStyle' isn't defined for the type 'Completer' 错误:未在 flutter 中为类型“FirebaseMessaging”定义方法“configure” - error: The method 'configure' isn't defined for the type 'FirebaseMessaging' in flutter Dart Flutter 未为类型“sqliteDaatabase”定义方法“getDatabasePath”。 错误 - Dart Flutter The method 'getDatabasePath' isn't defined for the type 'sqliteDaatabase'. Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM