Color object

Color is an immutable 32-bit value in the ARGB format (A transparent,R is red,G is GREE,B is blue,RGB is optical primary).

The logo of flutter, for example, is completely opaque. The red part of flutter is 0x42 (66), the GREE part is 0xA5 (165), and the blue part is 0xF5 (245). In generic “hash syntax” for color values, it could be written as # 42A5F5.

Here are some ways to write it

Color c = const Color(0xFF42A5F5); Color c = const Color.fromARGB(0xFF, 0x42, 0xA5, 0xF5); Color c = const Color.fromARGB(255, 66, 165, 245); Color c = const color.fromrgbo (66, 165, 245, 1.0);Copy the code

If you encounter problems with color that do not render, check whether the color value is 8-bit hexadecimal or 6-bit hexadecimal. If the color is 6-digit hexadecimal, it defaults to two zeros in front of it, so that the color is completely transparent.

Color c1 = const Color(0xFFFFFF); // fully transparent (invisible) c2 = const Color(0xFFFFFFFF); // Fully opaque white (visibleCopy the code

Also, colors defines some specific color types


Implementers:

  • ColorSwatch
  • MaterialStateColor

  • Constructor:

    Color(int value)                                                                                                                

    Construct the color const using the lower 32 bits of int as an argument

    Color.fromARGB(int a, int r, int g, int b)                                                                           

    Construct the color const with four low 8-bit integers of type int as arguments

    Color.fromRGBO(int r, int g, int b, double opacity)                                                            

    Create a color object using red,gree,blue,opacity(0 to 1 decimal) as parameters, similar to rgba() const in CSS


    Properties:

    Alpha → int: Transparency value, read only

    Blue → int: Blue color value, read-only

    Green → int: Gree color value, read only

    HashCode → int: Hash code value, read-only, override

    Opacity → double: a decimal value of opacity, read only

    Red → int: Red color value, read-only

    Value → int: 32-bit value of the current color, final

    RuntimeType → Type: the runtimeType of the object, which is read-only and inherited


    Methods:

    ComputeLuminance () → double: Returns luminance values between 0 and 1, with 0 indicating darkest and 1 indicating brightest

    ToString () → String: Returns a String representation of this object, override

    WithAlpha (int a) → Color: Returns a new Color, but the transparency is replaced by the passed argument, whose value ranges from 0 to 255

    WithBlue (int b) → Color: Returns a new Color, but the blue part is replaced by the passed argument, which has a value between 0 and 255

    WithGreen (int g) → Color: Returns a new Color, but the GREE part is replaced by the passed argument, which ranges from 0 to 255

    WithOpacity (double opacity) → Color: Returns a new Color, but the opacity is replaced by the passed parameter, which has a value between 0.0 and 1.0

    WithRed (int r) → Color: Returns a new Color, but the red part is replaced by the passed argument, whose value ranges from 0 to 255

    NoSuchMethod (Invocation) → Dynamic: This method is called when a method or attribute does not exist


    Operator method:

    Operator ==(dynamic other) → bool: Override the double equal sign operation


    Static method:

    AlphaBlend (Color foreground, Color background) → Color: Overwrites the first parameter as a transparent Color over the second parameter, and returns the combined Color

    Lerp (Color a, Color B, double t) → Color: Linear interpolation between two colors


    Original links, inaccuracies welcome to point out