Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 没有任何错误。“方法”;加上「;即使在初始化列表后也对null调用了_List_Flutter_Nosuchmethoderror - Fatal编程技术网

List 没有任何错误。“方法”;加上「;即使在初始化列表后也对null调用了

List 没有任何错误。“方法”;加上「;即使在初始化列表后也对null调用了,list,flutter,nosuchmethoderror,List,Flutter,Nosuchmethoderror,我在Flatter中创建了一个TextFormField。我有一个名为ParticipantsData的类,其中列出了一些属性。通过在另一个名为“RegistrationForm”的类中创建ParticipantsData类的对象,我可以访问和存储所有这些属性中的值。但是,即使已初始化列表类型的属性,我也无法将数据存储在这些属性中 我试过: - List.filled() - =[] - =[""] - List.generate() - List() - Li

我在Flatter中创建了一个TextFormField。我有一个名为ParticipantsData的类,其中列出了一些属性。通过在另一个名为“RegistrationForm”的类中创建ParticipantsData类的对象,我可以访问和存储所有这些属性中的值。但是,即使已初始化列表类型的属性,我也无法将数据存储在这些属性中

我试过:

 - List.filled() 
 - =[]
 - =[""]
 - List.generate()
 - List()
 - List<String>()
 - List<String>(length)
-List.filled()
- =[]
- =[""]
-List.generate()
-列表()
-列表()
-列表(长度)
我已经多次修改我的代码,并尝试了许多方法,但似乎没有任何效果。我不会在这里发布太多,因为我通常会在stackoverflow上找到解决方案,但这次我什么也找不到。 无法发布整个代码,因为它太长。以下是相关代码:

参与者数据类:

class ParticipantsData {
  List name = []; //members
  bool paymentstatus = false; //payment
  String email = ""; //email
  String address = ""; //address
  List contact = []; //contact
  String collegename = ""; //collegename
  String password = ""; //password
  String teamname = ""; //teamname
  var modules = List<String>(6); //modules

  ParticipantsData({
    this.name,
    this.email,
    this.contact,
    this.collegename,
    this.address,
    this.modules,
    this.password,
    this.paymentstatus,
    this.teamname,
  });
}
班级参与者数据{
列表名称=[];//成员
bool paymentstatus=false;//付款
字符串email=”“;//电子邮件
字符串地址=”;//地址
列出联系人=[];//联系人
字符串collegename=”“;//collegename
字符串password=”“;//密码
字符串teamname=”“;//teamname
var modules=List(6);//模块
参与者数据({
这个名字,
这是一封电子邮件,
这个,联系,,
这是我的名字,
这个地址,
这是一个模块,
这个密码,
这是支付状态,
这是我的名字,
});
}
以下是注册类别的相关代码:

class _RegistrationForm extends State<RegistrationForm> {
  final ParticipantsData data = new ParticipantsData();

//This is the onSaved method of a TextFormField, which is in a loop.
(String value) {                                         //Tried this...
                  data.name[i + 1] = value;
                  print('${data.name[i + 1]}');
                }),

(String value) {                                             //And this too...
                  data.name.add(value); 
                  print('${data.name[i + 1]}');
                }),
class\u注册表单扩展状态{
最终参与者数据=新参与者数据();
//这是位于循环中的TextFormField的onSaved方法。
(字符串值){//已尝试此操作。。。
data.name[i+1]=值;
打印('${data.name[i+1]}');
}),
(字符串值){//这也是。。。
数据。名称。添加(值);
打印('${data.name[i+1]}');
}),

在构造函数内部初始化时,分配的值将变为null。如果未在构造函数中包含字段,则这些字段将不会重置为null

但是,如果在创建实例时未提供字段,您可能希望在构造函数中分配值,并希望获得一些默认值。以下是如何执行此操作:

class MyClass {

  // Don't initialize here
  List x;
  int y;
  
  MyClass({
      this.x,
      this.y = 10, // If y is not assigned, it will take a default value of 10
  }) {
    // Constructor body
    this.x = this.x ?? []; // If x is not assigned, it will take a value of []
  }
}
请注意,可以直接为y提供默认值,因为10是一个常量值。您只能在构造函数参数列表中指定常量默认值。由于[]不是常量表达式或值,因此无法直接将其指定为默认值,因此,您需要定义构造函数体,指定x=[]如果x为空


您可以以类似的方式初始化其他字段。

在构造函数内初始化时,分配的值将变为null。如果未在构造函数中包含字段,则这些字段将不会重置为null

但是,如果在创建实例时未提供字段,您可能希望在构造函数中分配值,并希望获得一些默认值。以下是如何执行此操作:

class MyClass {

  // Don't initialize here
  List x;
  int y;
  
  MyClass({
      this.x,
      this.y = 10, // If y is not assigned, it will take a default value of 10
  }) {
    // Constructor body
    this.x = this.x ?? []; // If x is not assigned, it will take a value of []
  }
}
请注意,可以直接为y提供默认值,因为10是一个常量值。您只能在构造函数参数列表中指定常量默认值。由于[]不是常量表达式或值,因此无法直接将其指定为默认值,因此,您需要定义构造函数体,指定x=[]如果x为空

您可以用类似的方式初始化其他