Flutter: How to Align multiple ButtonBars such that the radio buttons are one below the other?

544 Views Asked by At

here you can see what I currently have: (I'm currently not allowed to insert this picture). I have two TabBars with two Radio Buttons each in a ListView, but it looks horrible. I would like to place the radio buttons one below the other, regardless of the length of the strings.

Here is my code:

 return ListView(
      children: <Widget>[
        //..
        ),
        Container(
            child: ButtonBar(
          alignment: MainAxisAlignment.spaceBetween, // I also tried every other setting here, but none works for me
          children: <Widget>[
            Radio(
              value: 1,
              groupValue: _selectedRadio,
              activeColor: corpColorPrimary,
              onChanged: (val) => setSelectedRadio(val),
            ),
            Text("a long String"),
            Radio(
              value: 2,
              groupValue: _selectedRadio,
              activeColor: corpColorPrimary,
              onChanged: (val) => setSelectedRadio(val),
            ),
            Text("Another long String"),
          ],
        )),

        Container(
          child: ButtonBar(
            alignment: MainAxisAlignment.start,
            children: <Widget>[
              Radio(
                value: 1,
                groupValue: _selectedRadio,
                activeColor: corpColorPrimary,
                onChanged: (val) => setSelectedRadio(val),
              ),
              Text("Hi"),
              Radio(
                value: 2,
                groupValue: _selectedRadio,
                activeColor: corpColorPrimary,
                onChanged: (val) => setSelectedRadio(val),
              ),
              Text(":)"),
            ],
          ),
        ),
        RaisedButton(
          child: Text("Next"),
          onPressed: () {},
        ),

How can I align the Radio buttons correctly?

2

There are 2 best solutions below

4
On

you can use Spacer(), widget between each Container(), widget and adjust them.

0
On

Take Row and in Row take two columns that will solve your issue.