43

I am trying to use it like this but it is giving me no color on text.

Color.fromARGB(1, 239 ~/ 255, 58 ~/ 255, 121 ~/ 255)
Shehbaz Khan
  • 1,892
  • 3
  • 24
  • 31

5 Answers5

87

Try using

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

Where r is for Red, g is for Green, b is for Blueand o is for opacity

Example:

Container(
                width: double.infinity,
                height: double.infinity,
                color: Color.fromRGBO(38, 38, 38, 0.4),
                child: Center(
                  child: CircularProgressIndicator(),
                ))
Prithvi Bhola
  • 3,041
  • 1
  • 16
  • 32
  • 1
    I tried doing this, but I'm getting the following error - The method 'fromRGBO' isn't defined for the type 'Color'. Try correcting the name to the name of an existing method, or defining a method named 'fromRGBO'.dartundefined_method – robben May 10 '20 at 09:42
7

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)
    )
)

Shababb Karim
  • 3,614
  • 1
  • 22
  • 35
7

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).

nonybrighto
  • 8,752
  • 5
  • 41
  • 55
4

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.

0

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