Reputation: 635
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
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
Reputation: 4392
is there anything wrong with this approach?
Icon(
Icons.camera_alt,
color: Colors.green.withOpacity(0.25),
)
Upvotes: 5
Reputation: 12693
There is an Opacity
widget you can use
Example
Opacity(
opacity: 0.25,
child: Icon(
Icons.ac_unit
),
)
Upvotes: 3