avoid-incorrect-image-opacity

Path
lint/correctness/avoid-incorrect-image-opacity
Default
Off, opt in
Origin
Falcon
Domain
flutter
Rule
73 of 512
flutter

Flags Opacity directly wrapping a Flutter Image, including named constructors. Prefer Image.opacity (or image color blending) to compositing the whole widget.

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) {
  Opacity(opacity: .5, child: Image(image: image));
  Opacity(opacity: .2, child: Image.asset("a"));
  const Opacity(opacity: .5, child: Image());
  f.Opacity(opacity: .5, child: f.Image.network("a"));
  new Opacity(opacity: .5, child: I.asset("a"));
}
Apply opacity directly to the Image instead of wrapping it in Opacity.
5void examples(Widget child, dynamic image, dynamic color, double size, String label) {
6 Opacity(opacity: .5, child: Image(image: image));
Apply opacity directly to the Image instead of wrapping it in Opacity.
6 Opacity(opacity: .5, child: Image(image: image));
7 Opacity(opacity: .2, child: Image.asset("a"));
Apply opacity directly to the Image instead of wrapping it in Opacity.
7 Opacity(opacity: .2, child: Image.asset("a"));
8 const Opacity(opacity: .5, child: Image());
Apply opacity directly to the Image instead of wrapping it in Opacity.
8 const Opacity(opacity: .5, child: Image());
9 f.Opacity(opacity: .5, child: f.Image.network("a"));
Apply opacity directly to the Image instead of wrapping it in Opacity.
9 f.Opacity(opacity: .5, child: f.Image.network("a"));
10 new Opacity(opacity: .5, child: I.asset("a"));

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) {
  Opacity(opacity: .5, child: SizedBox());
  Image(image: image, opacity: image);
  Opacity(opacity: .5);
  Opacity(opacity: .5, child: Container(child: Image()));
  Opacity(opacity: .5, child: child);
}

Configure avoid-incorrect-image-opacity

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-incorrect-image-opacity": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/correctness/avoid-incorrect-image-opacity: <reason>