Home > Back-end >  How to add opacity to a theme of context in flutter
How to add opacity to a theme of context in flutter

Time:01-22

I made a theme provider (dark and light theme) for my app after following some tutorials and it works. However, there are specific places where I would like to add some opacity. How can I do it given that I cannot add .withOpacity to a theme provider. You may refer to enter image description here

CodePudding user response:

Try this-

Theme.of(context).backgroundColor.withOpacity(0.6),

CodePudding user response:

When you set the iconTheme.color use the constructor Color.fromRGBO() instead, this works like (red,green,blue,opacity), and set the opacity value you need.

Example:

Color? theme = ThemeData.light().iconTheme.color;
//Before
theme = Colors.red;
//After
theme = const Color.fromRGBO(244, 67, 54, 0.5);
  •  Tags:  
  • Related