unnecessary_overrides
Unnecessary override.
Description
#The analyzer produces this diagnostic when an instance member overrides an inherited member but only invokes the overridden member with exactly the same arguments.
Example
#The following code produces this diagnostic because the method D.m
doesn't do anything other than invoke the overridden method:
class C {
int m(int x) => x;
}
class D extends C {
@override
int m(int x) => super.m(x);
}
Common fixes
#If the method should do something more than what the overridden method does, then implement the missing functionality:
class C {
int m(int x) => x;
}
class D extends C {
@override
int m(int x) => super.m(x) + 1;
}
If the overridden method should be modified by changing the return type or
one or more of the parameter types, making one of the parameters
covariant
, having a documentation comment, or by having additional
annotations, then update the code:
import 'package:meta/meta.dart';
class C {
int m(int x) => x;
}
class D extends C {
@mustCallSuper
@override
int m(int x) => super.m(x);
}
If the overriding method doesn't change or enhance the semantics of the code, then remove it:
class C {
int m(int x) => x;
}
class D extends C {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。