Demand is: Before you add information to determine textfiled there is no input information, otherwise the button is grayed out and can not be clicked.
Listener : textfiled which set the onchange attribute, and refresh setstate
TextField(
onChanged: (value) {
setState(() {
this.phone = value;
if (value.length >= 11)
this.phoneEnough = true;
else
this.phoneEnough = false;
});
},
Whether control buttons can click on : When the method onpressed button to null when you can not click, and then modify disabledcolor property, you can control the color.
Write a small case.
MaterialButton(
height: 50,
minWidth: double.infinity,
color: Color(0xff0096ff),
disabledColor: HitchColor.gray_999999,
onPressed: this._buttonClickListener(),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
child: Text("确认", textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontSize: 16)),
)
//点击事件,不能点击则返回null
_buttonClickListener() {
if(this.canBeClicked){
return (){//业务代码}
}else{
return null;
}
}