Lint don't override field in flutter
1,053
The fields id
and uid
already are defined within the UserEntity
class so it is redundant to declare them again as fields in the UserModel
class.
class UserModel extends UserEntity {
const UserModel({required int id, String? uid}) : super(id: id, uid: uid);
}
EDIT: as of dart 2.17 you can simplify the above code by using super initializers.
class UserModel extends UserEntity {
const UserModel({required super.id, super.uid});
}
Author by
unice
Updated on January 02, 2023Comments
-
unice over 1 year
I'm new in using Lint and I'm getting a blue underline on my
UserModel
variables with a message ofDon't override fields
andAnnotate overridden members
. I'm having a hard time understanding the Good and Bad rules in the example docs. I still get the same message after adding@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]; }
-
jamesdlin over 2 yearsThe
overridden_fields
lint is warning you that you're overriding a field. Adding an@override
attribute won't help. If you don't want the warning, don't override the base fields, use a getter and/or setter in the derived class instead if possible, or use// ignore: overridden_fields
to suppress the lint. Also see github.com/dart-lang/linter/issues/2428.
-