Divide a Row into two equal halves in Flutter

Viewed 3734

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?

2 Answers

Try this

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: [
    Expanded(child: Center(child: TextButton(...))),
    VerticalDivider(width: 1.0),
    Expanded(child: Center(child: TextButton(...))),
  ],
),

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: ...
              ),
          ]
        ),
      ],
    );
  }
Related