avoid-missing-image-alt

Path
lint/a11y/avoid-missing-image-alt
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
87 of 512
flutter

Requires semanticLabel on Flutter Image and imageSemanticLabel on FadeInImage. Explicitly null labels are missing; empty labels and dynamic label expressions are accepted. Explicit true or dynamic excludeFromSemantics values are exempt; only an absent flag or literal false proves an image needs a label.

Invalid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef I = Image;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  Image(image: image);
  Image.asset("a");
  new Image.network("a", semanticLabel: null);
  const Image(excludeFromSemantics: false);
  f.Image.memory(image);
}
Provide a semantic label for this image, or explicitly exclude decorative images from semantics.
5void examples(Widget child, dynamic image, dynamic color, double size, String label) {
6 Image(image: image);
Provide a semantic label for this image, or explicitly exclude decorative images from semantics.
6 Image(image: image);
7 Image.asset("a");
Provide a semantic label for this image, or explicitly exclude decorative images from semantics.
7 Image.asset("a");
8 new Image.network("a", semanticLabel: null);
Provide a semantic label for this image, or explicitly exclude decorative images from semantics.
8 new Image.network("a", semanticLabel: null);
9 const Image(excludeFromSemantics: false);
Provide a semantic label for this image, or explicitly exclude decorative images from semantics.
9 const Image(excludeFromSemantics: false);
10 f.Image.memory(image);

Valid

example.dartdart
import 'package:flutter/widgets.dart';
import 'package:flutter/widgets.dart' as f;
typedef I = Image;
void callback() {}
void examples(Widget child, dynamic image, dynamic color, double size, String label) {
  Image(semanticLabel: "Photo");
  Image.asset("a", semanticLabel: label);
  Image.network("a", excludeFromSemantics: true);
  const Image(semanticLabel: "Icon");
  I.memory(image, semanticLabel: "Preview");
}

Configure avoid-missing-image-alt

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "a11y": {
        "avoid-missing-image-alt": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/a11y/avoid-missing-image-alt: <reason>