TextFormField根据单选按钮启用/禁用选中的Flutter

时间:2019-09-01 15:02:35

标签: flutter dart flutter-layout

在扑通状态下,如何根据单选按钮启用/禁用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停用单选按钮已选中

1 个答案:

答案 0 :(得分:2)

您可以将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.
),