Mo711
Mo711

Reputation: 635

Change opacity of an Icon

I am trying to change the opacity of an icon, when it is present in the code in this format:

child: Icon(Icons.camera_alt),

I want to do it in the same way you can do it with a color:

color: Colors.green.withOpacity(0.25),

Is there a way to do this?

Upvotes: 2

Views: 4053

Answers (3)

kiwicmc
kiwicmc

Reputation: 26

For me, this works:

Icon(Icons.pause, color: Colors.white70)

as does this:

Icon(Icons.pause, color: Color(0xB3FFFFFF))

but this fails:

    Icon(Icons.pause, color: Colors.white.withOpacity(70))

======== Exception caught by widgets library =======================================================
The following assertion was thrown building LiveCountdownTimer(dirty, state: LiveCountdownTimerState#25b2d):
'dart:ui/painting.dart': Failed assertion: line 189 pos 12: '<optimized out>': is not true.

The relevant error-causing widget was: 
  CountdownTimer CountdownTimer:file:///Users/xxx/lib/screen/aaa.dart:637:18
When the exception was thrown, this was the stack: 
#2      Color.withOpacity (dart:ui/painting.dart:189:12)

Upvotes: 0

LonelyWolf
LonelyWolf

Reputation: 4392

is there anything wrong with this approach?

    Icon(
      Icons.camera_alt,
      color: Colors.green.withOpacity(0.25),
    )

Upvotes: 5

Josteve Adekanbi
Josteve Adekanbi

Reputation: 12693

There is an Opacity widget you can use

Example

 Opacity(
            opacity: 0.25,
            child: Icon(
              Icons.ac_unit
            ),
          )

Upvotes: 3

Related Questions