I have a row widget and I want some Text
to be in the very center or the Row
and an Icon
that will be to the left of it, and changing how far left the Icon
is it is should not affect the position of the Text
. Here is my code:
Widget build(BuildContext context) {
return GestureDetector(
child: FractionallySizedBox(
heightFactor: 0.8,
child: Container(
color: Color(0xff2a2a2a),
child: Column(
children: [
Row(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Icon(Icons.egg)),
Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Text("TEST",
style: TextStyle(
fontSize: 24,
color: Color(0xffE0E0E0),
)),
),
Row(
children: [
Text("TEST"),
],
)
],
)
],
)
],
)),
));
}
}
Note that I haven’t actually made any adjustments to try to create this effect. That is because everything I have tried does not work. Here is what I have tried:
- Wrapped my
Text
inAlign
widget - Include
mainAxisAlignment: MainAxisAlignment.center
inRow
. This will center theText
andIcon
, but I cannot adjust the position of theIcon
without affecting the position of theText
and will affect possible future additions to theRow
- Wrap
Text
or/andPadding
withCenter
. Both Icon andText
remain in the top left position - It’s obvious that I’ve thought about using
Padding
butPadding
doesn’t seem to be a very good solution and doesn’t seem to generalize well.
I also want to clarify that the problem is occurring in the Row
that is furthest up. Any and all help and suggestions are greatly appreciated
2
Answers
Perhaps you should use Stack instead.
I believe that you’re looking for
Expanded()
/Spacer()
which allow proportionally sizing children ofColumn
or aRow
.Updated code: