简体   繁体   中英

How do I use RGB color in Flutter?

我正在尝试像这样使用它,但它没有给我文本颜色。

Color.fromARGB(1, 239 ~/ 255, 58 ~/ 255, 121 ~/ 255)

Try using

Color.fromRGBO(38, 38, 38, 0.4)

Where r is for Red , g is for Green, b is for Blue and o is for opacity

Example:

Container(
                width: double.infinity,
                height: double.infinity,
                color: Color.fromRGBO(38, 38, 38, 0.4),
                child: Center(
                  child: CircularProgressIndicator(),
                ))

You can also use the hexadecimal representation Color(0XFF212845) .
Comment from source

/// In other words, if AA is the alpha value in hex, RR the red value in hex,
/// GG the green value in hex, and BB the blue value in hex, a color can be
/// expressed as const Color(0xAARRGGBB) .

I am using this code block for a personal project of mine in order to show text with a specific color using Color.fromRGBO , first parameter is Red , second is Green , third is Blue and last parameter defines the Opacity .

Text(
    "This is a sample text",
     textAlign: TextAlign.center,
     style: TextStyle(
             color: Color.fromRGBO(255, 179, 102, 1)
    )
)

increase alpha(first argument) so you can see it. example:- color: Color.fromARGB(255, 255, 0, 0)

If you want to specify opacity as a double value between 0.0 (transparent) and 1.0 (fully opaque), use Color.fromRGBO() . The opacity value is the last parameter.

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

But if you want to specify opacity as an integer value between 0 (transparent) and 255 (fully opaque), use Color.fromARGB() . The opacity value is the first parameter.

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

The r , g , b parameters of both methods are integer values between 0 and 255.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM