opacity_around_image
Reports an Opacity whose child is an Image. Pass the opacity to the image instead.
- Tier
- advisory
- Scope
- Flutter
- Lowest preset
- recommended
- Fix
- none
What it reports
Section titled “What it reports”A Flutter Opacity whose child is itself a Flutter Image, by any of its constructors. The violation is on the name of the Opacity constructor.
An Opacity whose opacity is the literal 0 or 1 is not reported, since Flutter paints no layer for either.
The rule reports nothing in a package that does not use Flutter.
The Opacity paints the image into a layer of its own and blends that layer. That costs far more than the image painting itself with the opacity, through its opacity argument.
Example
Section titled “Example”Opacity(opacity: 0.5, child: Image.asset('assets/logo.png'))Image.asset( 'assets/logo.png', opacity: const AlwaysStoppedAnimation(0.5),)Rule parameters
Section titled “Rule parameters”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. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Why this place is fine.// ignore: opacity_around_image// ignore_for_file: assay/opacity_around_image silences it in a whole file, and the prefixed // ignore: assay/opacity_around_image works too. See Suppressions.