颤动中的单选按钮对齐
Radio Button Alignment in flutter
我是flutter的新手。我想对齐单选按钮。即无论文本在哪里,单选按钮都应该按列对齐。
我正在使用 Column
小部件,然后在其中使用 Row
小部件,但得到以下结果。
代码在这里
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio button 1')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio 2')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Test')
],
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('RB 1')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Btn Radio 2')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Rad 3')
],
),
],
),
],
),
);
}
您可以使用以下几行希望这对您有所帮助
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text('Radio button 1'),
)
],
),
flex: 1,
),
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Radio 2'))
],
),
flex: 1,
),
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Test'))
],
),
flex: 1,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('RB 1'))
],
),
),
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Btn Radio 2'))
],
),
),
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text('Rad 3'),
)
],
),
),
],
),
],
),
大家可以根据屏幕比较我用的widget。你可以用 Flexible 或者 Expanded
Container(
child: Column(
children: [
Row(
children: [
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text(
'Radio button 1',
maxLines: 2,
))
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio 2')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Test')
],
),
),
],
),
Row(
children: [
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('RB 1')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Btn Radio 2')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Rad 3')
],
),
),
],
),
],
),
)
我是flutter的新手。我想对齐单选按钮。即无论文本在哪里,单选按钮都应该按列对齐。
我正在使用 Column
小部件,然后在其中使用 Row
小部件,但得到以下结果。
代码在这里
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio button 1')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio 2')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Test')
],
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('RB 1')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Btn Radio 2')
],
),
Row(
children: [
Radio(value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Rad 3')
],
),
],
),
],
),
);
}
您可以使用以下几行希望这对您有所帮助
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text('Radio button 1'),
)
],
),
flex: 1,
),
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Radio 2'))
],
),
flex: 1,
),
Expanded(
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Test'))
],
),
flex: 1,
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('RB 1'))
],
),
),
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(child: Text('Btn Radio 2'))
],
),
),
Expanded(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text('Rad 3'),
)
],
),
),
],
),
],
),
大家可以根据屏幕比较我用的widget。你可以用 Flexible 或者 Expanded
Container(
child: Column(
children: [
Row(
children: [
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Expanded(
child: Text(
'Radio button 1',
maxLines: 2,
))
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Radio 2')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Test')
],
),
),
],
),
Row(
children: [
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('RB 1')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Btn Radio 2')
],
),
),
Flexible(
flex: 1,
child: Row(
children: [
Radio(
value: 1, groupValue: 'null', onChanged: (index) {}),
Text('Rad 3')
],
),
),
],
),
],
),
)