Lint 不会覆盖 flutter 中的字段
Lint don't override field in flutter
我是 Lint 的新手,我的 UserModel
变量上有一条蓝色下划线,并带有消息 Don't override fields
和 Annotate overridden members
。我很难理解示例文档中的 Good 和 Bad 规则。添加 @override
.
后我仍然收到相同的消息
class UserModel extends UserEntity {
final int id;
final String? uid;
const UserModel(
{required this.id,
this.uid})
: super(
id: id,
uid: uid,
);
}
//
class UserEntity extends Equatable {
const UserEntity({
required this.id,
this.uid,
this.provider,
});
final int id;
final String? uid;
static const empty = UserEntity(id: 0, uid: '');
@override
List<Object> get props => [id];
}
字段 id
和 uid
已经在 UserEntity
class 中定义,因此再次将它们声明为 UserModel
中的字段是多余的class.
class UserModel extends UserEntity {
const UserModel({required int id, String? uid}) : super(id: id, uid: uid);
}
编辑:从 dart 2.17 开始,您可以使用超级初始化程序简化上述代码。
class UserModel extends UserEntity {
const UserModel({required super.id, super.uid});
}
我是 Lint 的新手,我的 UserModel
变量上有一条蓝色下划线,并带有消息 Don't override fields
和 Annotate overridden members
。我很难理解示例文档中的 Good 和 Bad 规则。添加 @override
.
class UserModel extends UserEntity {
final int id;
final String? uid;
const UserModel(
{required this.id,
this.uid})
: super(
id: id,
uid: uid,
);
}
//
class UserEntity extends Equatable {
const UserEntity({
required this.id,
this.uid,
this.provider,
});
final int id;
final String? uid;
static const empty = UserEntity(id: 0, uid: '');
@override
List<Object> get props => [id];
}
字段 id
和 uid
已经在 UserEntity
class 中定义,因此再次将它们声明为 UserModel
中的字段是多余的class.
class UserModel extends UserEntity {
const UserModel({required int id, String? uid}) : super(id: id, uid: uid);
}
编辑:从 dart 2.17 开始,您可以使用超级初始化程序简化上述代码。
class UserModel extends UserEntity {
const UserModel({required super.id, super.uid});
}