Checkbox form validation

前端 未结 4 2356
栀梦
栀梦 2021-02-20 11:27

How can I validate a checkbox in a Flutter Form? Every other validation works fine, but the checkbox doesn\'t show an Error. Here is my code:

FormFi         


        
4条回答
  •  悲&欢浪女
    2021-02-20 12:14

    You could try something like this :

    CheckboxListTile(
      value: checkboxValue,
      onChanged: (val) {
        setState(() => checkboxValue = val
      },
      subtitle: !checkboxValue
          ? Text(
              'Required.',
              style: TextStyle(color: Colors.red),
            )
          : null,
      title: new Text(
        'I agree.',
        style: TextStyle(fontSize: 14.0),
      ),
      controlAffinity: ListTileControlAffinity.leading,
      activeColor: Colors.green,
    );
    

提交回复
热议问题