5

I have a Row widget inside a Card, and I want to divide the Row perfectly in half the width of the card and put some centered text in each half. So the separation in half of the row has to be fixed and each text has to be centered in the half where it is. Here is an example:

enter image description here

Any ideas?

Fabio
  • 376
  • 6
  • 19

2 Answers2

12

Try this

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Expanded(child: Center(child: TextButton(...))),
    VerticalDivider(width: 1.0),
    Expanded(child: Center(child: TextButton(...))),
  ],
),
BambinoUA
  • 6,126
  • 5
  • 35
  • 51
  • 1
    Almost.. with a Center widget, it works. `Expanded(child: Center(child: TextButton(...))),`. Thank you! – Fabio Jan 28 '21 at 21:01
4

In my case I tried like this

 @override
  Widget build(BuildContext context) {
    final _screen =  MediaQuery.of(context).size;
    return Column(
      children: [
        Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                width: _screen.width * 0.45,
                child: ...
              ),
              VerticalDivider(width: 1.0),
              Container(
                width: _screen.width * 0.45,
                child: ...
              ),
          ]
        ),
      ],
    );
  }
Aathi
  • 2,599
  • 2
  • 19
  • 16