new in flutter
I’m having a row, and I’m trying to center an image inside of it, and another image that will be positioned exactly 24 points from the right of the screen.
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).colorScheme.secondaryContainer,
height: 157,
width: double.infinity,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 24,
color: Colors.black,
),
setDeviceIcon(),
setArrow(),
],
),
);
}
Container setArrow() {
return Container(
color: Colors.yellow,
child: IconButton(
onPressed: () {},
icon: const Icon(
Icons.chevron_right,
)),
margin: EdgeInsets.only(right: 24),
);
}
result should be like this:
2
Answers
Use
padding
on Container instead of providing margin onsetArrow
If you want those images to be in the center of the screen (or Row in this case), change the mainAxisAlignment attribute to:
You want to center the elements inside the Row and then apply spacing between them with Margin, Padding or SizedBox.
The spaceBetween property, will force the children to align along all the Row’s length applying space between them. Take a look at this:
example of spacing in rows