deprecated_member_use_from_same_package
Avoid using deprecated elements from within the package in which they are declared.
Details
#Elements that are annotated with @Deprecated
should not be referenced from within the package in which they are declared.
AVOID using deprecated elements.
...
BAD:
// Declared in one library:
class Foo {
@Deprecated("Use 'm2' instead")
void m1() {}
void m2({
@Deprecated('This is an old parameter') int? p,
})
}
@Deprecated('Do not use')
int x = 0;
// In the same or another library, but within the same package:
void m(Foo foo) {
foo.m1();
foo.m2(p: 7);
x = 1;
}
Deprecated elements can be used from within other deprecated elements, in order to allow for the deprecation of a collection of APIs together as one unit.
GOOD:
// Declared in one library:
class Foo {
@Deprecated("Use 'm2' instead")
void m1() {}
void m2({
@Deprecated('This is an old parameter') int? p,
})
}
@Deprecated('Do not use')
int x = 0;
// In the same or another library, but within the same package:
@Deprecated('Do not use')
void m(Foo foo) {
foo.m1();
foo.m2(p: 7);
x = 1;
}
Enable
#To enable the deprecated_member_use_from_same_package
rule, add deprecated_member_use_from_same_package
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- deprecated_member_use_from_same_package
If you're instead using the YAML map syntax to configure linter rules, add deprecated_member_use_from_same_package: true
under linter > rules:
linter:
rules:
deprecated_member_use_from_same_package: true
Unless stated otherwise, the documentation on this site reflects Dart 3.7.0. Page last updated on 2025-01-27. View source or report an issue.