Reputation: 552
I was trying to center the icon in a circular background but it failed even if I use a center widget as child unless increase container size.
Container(
height: 22,
width: 22,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffF7825C),
),
child: Center(
child: Icon(
Icons.add,
color: Colors.white,
),
),
)
Upvotes: 0
Views: 7671
Reputation: 417
you can try this code :-
Container(
alignment: Alignment.center,
height: 22,
width: 22,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffF7825C),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 22
),
)
Upvotes: 0
Reputation: 31
Issue can be solve by giving size to Icon
Container(
width: 40,
height: 20,
child: Icon(
Icons.arrow_right_alt_outlined,
color: Colors.white,
size: 20,),
),
the above thing works because now we have the container which can contain whole icons size ( 40x20(container) can contain 20(icon)) but if this icons size gets bigger than container dimension there we meshed up the centering of icon inside container
hope this explanation works!
Upvotes: 1
Reputation: 501
Try this:
Container(
alignment: Alignment.center,
height: 22,
width: 22,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffF7825C),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 22
),
)
Upvotes: 5
Reputation: 6089
You can also use RawMaterialButton
, You can set it like this
RawMaterialButton(
onPressed: () {},
fillColor: Color(0xffF7825C),
child: Icon(
Icons.add,
size: 22.0,
color: Colors.white,
),
shape: CircleBorder(),
)
Upvotes: 2
Reputation: 3469
use the following :
Container(
height: 22,
width: 22,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffF7825C),
),
alignment: Alignment.center,
child: Icon(
Icons.add,
color: Colors.white,
),
)
Upvotes: -2
Reputation: 304
You need to set the size of your icon with size
attribute, so your Icon widget should look like this
Icon(
Icons.add,
color: Colors.white,
size: 22
)
Upvotes: 2