use_super_parameters
Use super-initializer parameters where possible.
This rule is currently experimental and available as of Dart 2.17.
Rule sets: recommended, flutter
This rule has a quick fix available.
Details
#"Forwarding constructor"s, that do nothing except forward parameters to their superclass constructors should take advantage of super-initializer parameters rather than repeating the names of parameters when passing them to the superclass constructors. This makes the code more concise and easier to read and maintain.
DO use super-initializer parameters where possible.
BAD:
class A {
A({int? x, int? y});
}
class B extends A {
B({int? x, int? y}) : super(x: x, y: y);
}
GOOD:
class A {
A({int? x, int? y});
}
class B extends A {
B({super.x, super.y});
}
Usage
#To enable the use_super_parameters
rule,
add use_super_parameters
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- use_super_parameters
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。