Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter : Align radio in wrap widget in column

I found one duplicate question on this but that was not created dynamically as I do here which is using a List because I might want to add new items. So how do I align cause my 2nd column of radios arent vertically aligned.
radio on the second column is not aligned
Here’s my code:

List<OptionList> optList = [
    OptionList(name: "Super Fast", total: 20, index: 1, price: 50),
    OptionList(name: "Fast", total: 6, index: 2, price: 20),
    OptionList(name: "Regular", total: 5, index: 3, price: 10),
    OptionList(name: "Slow", total: 5, index: 3, price: 5),
  ];

Wrap(
    spacing: 20,
    runSpacing: 15,
    direction: Axis.horizontal,
    alignment: WrapAlignment.spaceBetween,
    runAlignment: WrapAlignment.spaceEvenly,
    children: optList.map((data) => Row(
                  mainAxisSize: MainAxisSize.min,
                   children: [
                        Radio(
                           value: data.name,
                           groupValue: data.index,
                           onChanged: (val) {
                               setState(() {
                                   speed = data.name;
                                   id = data.index;
                               });
                           }),
                           Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                 Text("${data.total}" ' ' "${data.name}"),
                                 Text('~'"${data.price}" ' ')
                              ],
                           ),
                       ],)).toList(),
    ),

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Wrap children are different sizes and alignment: WrapAlignment.spaceBetween,, that why you are having this issue. You can provide fixed with that solves the issue but this also depend on text size. If you are fixed with these string 120 width is enough.

children: optList
    .map(
      (data) => SizedBox(
        width: 120,
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Radio(
                value: data.name,
                groupValue: data.index,
                onChanged: (val) {}),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${data.total}" ' ' "${data.name}"),
                Text('~' "${data.price}" ' ')
              ],
            ),
          ],
        ),
      ),
    )
    .toList(),

If you have overflow with long text, you can wrap Column with Expanded widget.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading