我有两个用于注册表单的单选按钮,我希望它们水平相邻,我已经使用了,Row但是随附的文本不会选择单选按钮,只有选择单选按钮本身才能执行此操作...
我知道 RadioListTile 允许使用单选按钮和标签,但据我所知它只能垂直定位。将其包裹Text在 InkWell 中可能可行,但我不确定如何保存状态。
Row(
children: <Widget>[
Row(
children: <Widget>[
Radio(
value: 0,
groupValue: _radioGroupValue,
activeColor: Colors.white,
onChanged: (int value) {
changeRadioSelection(value);
}),
Text(
'Client',
style: TextStyle(color: Colors.white, fontSize: 15.0),
)
],
),
SizedBox(
width: 20.0,
),
Row(
children: <Widget>[
Radio(
value: 1,
groupValue: _radioGroupValue,
onChanged: (int value) {
changeRadioSelection(value);
},
activeColor: Colors.white,
),
Text(
'Customer',
style: TextStyle(color: Colors.white, fontSize: 15.0),
)
],
)
],
),
Run Code Online (Sandbox Code Playgroud)
状态控制方法:
void changeRadioSelection(int value) {
setState(() {
_radioGroupValue = value;
print('Radio butto selected: $value');
});}
Run Code Online (Sandbox Code Playgroud)
除了文本不选择单选按钮之外,这工作正常。有没有办法做到这一点。如果我的用户界面是水平的而不是垂直的,它看起来会更干净。
两种解决方案:
InkWell(
onTap: () => changeRadioSelection(1),
child: Row(
children: <Widget>[
Radio(
value: 1,
groupValue: _radioGroupValue,
onChanged: (int value) {
changeRadioSelection(value);
},
activeColor: Colors.grey,
),
Text(
'Customer',
style: TextStyle(color: Colors.black, fontSize: 15.0),
)
],
),
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
971 次 |
| 最近记录: |