///不可点击按钮颜色
const Color disableBtnColor = Color(0xFF7FABF4);
///可点击按钮颜色
const Color enableBtnColor = Color(0xFF0058E9);
///定义Button
Widget normalButton(BuildContext context,VoidCallback onPressed) {
return Container(
height: 40,
margin: EdgeInsets.only(top: 25),
width: MediaQuery.of(context).size.width,
child: RaisedButton(
elevation: 0,
color: enableBtnColor,
disabledColor: disableBtnColor,
onPressed: onPressed,
child: Text('Ok',
style: TextStyle(
color: Colors.white,
fontSize: 14,
decoration: TextDecoration.none,
)),
));
}
使用方法
bool _canClick = false; //这里控制是否可点击或禁用
_buildBtn() {
return normalButton(context,
_canClick ? () => onBtnPressed() : null); //传空就是禁用
}
void onBtnPressed() {
///TODO
}