为什么不能这样做?
abstract class IUserDto {
String id;
String firstName;
String lastName;
String email;
}
class UserLogicItem implements IUserDto {
UserLogicItem({this.id, this.firstName, this.lastName, this.email});
@override
final String id;
@override
final String firstName;
@override
final String lastName;
@override
final String email;
}
我收到此错误:
缺少“ setter IUserDto.email”,“ setter”的具体实现 IUserDto.firstName”,“设置IUserDto.id”和“设置” IUserDto.lastName”。尝试实施缺少的方法,或者使 class abstract.dart(non_abstract_class_inherits_abstract_member)
但是我想创建一个类合同,其中具体类必须具有这些属性。
答案 0 :(得分:2)
class UserLogicItem implements IUserDto {
UserLogicItem({this.id, this.firstName, this.lastName, this.email});
@override
String email;
@override
String firstName;
@override
String id;
@override
String lastName;
}
答案 1 :(得分:1)
在UserLogicItem
中添加缺少的二传手,它将解决此问题。您可以按Ctrl + Enter
快速添加缺少的替代,也可以使用班级中的Ctrl + O
检查缺少的替代。
class UserLogicItem implements IUserDto {
UserLogicItem({this.id, this.firstName, this.lastName, this.email});
@override
final String id;
@override
final String firstName;
@override
final String lastName;
@override
final String email;
@override
void set email(String _email) {
// TODO: implement email
}
@override
void set firstName(String _firstName) {
// TODO: implement firstName
}
@override
void set id(String _id) {
// TODO: implement id
}
@override
void set lastName(String _lastName) {
// TODO: implement lastName
}
}