prefer_mixin
Prefer using mixins.
Details
#Dart 2.1 introduced a new syntax for mixins that provides a safe way for a mixin
to invoke inherited members using super
. The new style of mixins should always
be used for types that are to be mixed in. As a result, this lint will flag any
uses of a class in a with
clause.
BAD:
dart
class A {}
class B extends Object with A {}
OK:
dart
mixin M {}
class C with M {}
Enable
#To enable the prefer_mixin
rule,
add prefer_mixin
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- prefer_mixin
If you're instead using the YAML map syntax to configure linter rules,
add prefer_mixin: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
prefer_mixin: true
除非另有说明,文档之所提及适用于 Dart 3.7.0 版本,本页面最后更新时间: 2025-01-27。 查看文档源码 或者 报告页面问题。