Skip to content

image_without_semantics

Reports a Flutter Image given no semanticLabel and no excludeFromSemantics. Say what it shows, or mark it decorative.

Tier
advisory
Scope
Flutter
Lowest preset
strict
Fix
none

A Flutter Image, made by any of its constructors, that is given no semanticLabel and no excludeFromSemantics. The violation is on the constructor.

It does not report:

  • an image with excludeFromSemantics: true, the explicit decorative signal;
  • an image given either argument with any value, as a wrapper widget passes its own on;
  • an image that a Semantics, ExcludeSemantics, MergeSemantics, BlockSemantics or Tooltip built around it in the same file describes or hides.

Inside a wrapper widget, such as an image of a design system, the Image is reported where the wrapper takes no label to pass on.

A screen reader announces such an image as an image, and nothing of what it shows. A decorative image says so with excludeFromSemantics: true; an image that shows something says what.

The rule is advisory and in strict only: many projects do not write labels yet, and decorative images need the explicit signal.

Violating
Widget avatar(String path) => Image.file(File(path));
Corrected
Widget avatar(String path, String name) =>
Image.file(File(path), semanticLabel: 'Photo of $name');

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Why it stays as written here.
// ignore: image_without_semantics

// ignore_for_file: assay/image_without_semantics silences it in a whole file, and // ignore: assay/image_without_semantics with the prefix works too. See Suppressions.