我如何解决 flutter class 代码中的这个错误
How can I solved this error in flutter class code
我写这个class
class Profile {
String email;
String password;
Profile({this.email, this.password});
}
但是它说
"The parameter 'email' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.dartmissing_default_value_for_parameter"
通过添加要求:
class Profile {
String email;
String password;
Profile({
required this.email,
required this.password,
});
}
通过添加可选:
class Profile {
String? email;
String? password;
Profile({
this.email,
this.password,
});
}
通过添加默认值:
class Profile {
String email;
String password;
Profile({
this.email = "mail@gmail.com",
this.password = "123",
});
}
您必须让他们接受一个 null
值。
class Profile {
String? email;
String? password;
Profile({this.email, this.password});
}
我写这个class
class Profile {
String email;
String password;
Profile({this.email, this.password});
}
但是它说
"The parameter 'email' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Try adding either an explicit non-'null' default value or the 'required' modifier.dartmissing_default_value_for_parameter"
通过添加要求:
class Profile {
String email;
String password;
Profile({
required this.email,
required this.password,
});
}
通过添加可选:
class Profile {
String? email;
String? password;
Profile({
this.email,
this.password,
});
}
通过添加默认值:
class Profile {
String email;
String password;
Profile({
this.email = "mail@gmail.com",
this.password = "123",
});
}
您必须让他们接受一个 null
值。
class Profile {
String? email;
String? password;
Profile({this.email, this.password});
}