在flutter中选中后,如何根据单选按钮启用/禁用TextFormField
?
new Text('Allpages? :', style: new TextStyle(height: 1.0, fontSize: 15.2, fontWeight: FontWeight.bold,)),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Radio(
value: 0,
groupValue: _printAllValue,
onChanged: _setPrintAllValue,
),
new Text('Yes'),
new Radio(
value: 1,
groupValue: _printAllValue,
onChanged: _setPrintAllValue,
),
new Text('No'),
],
),
new Padding(padding: new EdgeInsets.all(5.0)),
new Text('Start and End pages :', style: new TextStyle(height: 1.0, fontSize: 15.2, fontWeight: FontWeight.bold,)),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
width: 200,
child: new TextFormField(
style: TextStyle(color: Colors.black87),
textInputAction: TextInputAction.done,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'Start Page',
),
),
),
new Container(
width: 200,
child: new TextFormField(
style: TextStyle(color: Colors.black87),
textInputAction: TextInputAction.done,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'End Page',
),
),
),
],
),
new Padding(padding: new EdgeInsets.all(10.0)),
我需要先检查“
No
”单选按钮,然后将“起始页”,“结束页”设为激活,并选中yes
单选按钮时,将停用 最佳答案
您可以将TextFormField
包装在AbsorbPointer
中,并处理absorb
属性,例如:
bool _disable = false; // set this to false initially
AbsorbPointer(
absorbing: _disable, // true makes TextFormField disabled and vice-versa
child: TextFormField(),
)
每当您要禁用以上字段时,都可以更改其属性,并实际上从
Radio
中获取值并将其分配给_disable
编辑:
TextFormField中有一个属性,您可以更改它
TextFormField(
enabled: !_disable, // set to false to disable it.
),
关于flutter - TextFormField根据单选按钮启用/禁用选中的Flutter,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57747067/