avoid-missing-image-alt
added in: 1.7.0
warning
Warns when an Image
widget does not have a semanticLabel
.
⚙️ Config
Set allow-empty
(default is true
) to configure whether an empty string value is allowed to be used as label.
dart_code_metrics:
...
rules:
...
- avoid-missing-image-alt:
allow-empty: true
Example
❌ Bad:
void main() {
const Image(key: 'hello'); // LINT
Image.asset(key: 'hello'); // LINT
const FadeInImage(key: 'hello'); // LINT
FadeInImage.assetNetwork(key: 'hello'); // LINT
}
✅ Good:
void main() {
const Image(key: 'hello', semanticLabel: 'some');
Image.asset(key: 'hello', semanticLabel: 'thing');
const FadeInImage(key: 'hello', imageSemanticLabel: 'some');
FadeInImage.assetNetwork(key: 'hello', imageSemanticLabel: 'thing');
}