Reputation: 34170
Is it possible to add a background color to the Icon image? I am using the below code to render icon.
Icon(
Icons.check_circle_outline,
size: 35.0,
)
I want output like below when the image is drawn
Upvotes: 1
Views: 3610
Reputation: 1
Depending on the shape and size of your icon, stacking your icon on top of a square widget that has your desired background color can work.
Stack(alignment: Alignment.center, children: [
Container(height: 20.0, width: 20.0, color: Colors.black),
Icon(Icons.photo_size_select_actual, color: Colors.cyanAccent, size: 35.0)
]),
You could stack on top of a circular widget as well.
Upvotes: -1
Reputation: 34170
Below Solution provide an exact output
Container(
color: Colors.blue,
padding: EdgeInsets.all(5),
child: ClipOval(
child: Container(
color: Colors.green,
child: Icon(
Icons.check,
color: Colors.white,
size: 30,
),
),
),
)
Output:
Upvotes: 0
Reputation: 382
If you try to get the icon exactly like in your picture then this is not possible. The icon check_circle_outline
looks like the following:
So you have a checkmark and a circle all in one icon. What you want is to change only parts of the icon (in your case the circle)
But if you just want to add a background color behind the icon, then you can do it like Viren said:
Container(
color: Colors.blue,
child: Icon(
Icons.check_circle_outline,
size: 35.0,
),
)
If you want the exact same icon as in your picture, use another icon check
circle and this snippet:
ClipOval(
child: Container(
color: Colors.green,
child: Icon(
Icons.check,
color: Colors.white,
size: 35.0,
),
),
);
Upvotes: 3
Reputation: 1348
How about this?
Container(
color: Colors.blue,
child: Icon(
Icons.check_circle_outline,
size: 35.0,
),
),
Upvotes: 0