Color.fromRGBO constructor Null safety

const Color.fromRGBO(
  1. int r,
  2. int g,
  3. int b,
  4. double opacity
)

Create a color from red, green, blue, and opacity, similar to rgba() in CSS.

  • r is red, from 0 to 255.
  • g is green, from 0 to 255.
  • b is blue, from 0 to 255.
  • opacity is alpha channel of this color as a double, with 0.0 being transparent and 1.0 being fully opaque.

Out of range values are brought into range using modulo 255.

See also fromARGB, which takes the opacity as an integer value.

Implementation

const Color.fromRGBO(int r, int g, int b, double opacity) :
  value = ((((opacity * 0xff ~/ 1) & 0xff) << 24) |
            ((r                    & 0xff) << 16) |
            ((g                    & 0xff) << 8)  |
            ((b                    & 0xff) << 0)) & 0xFFFFFFFF;