如何在Flutter中启用/禁用ElevatedButton
有人知道如何启用/禁用 Flutter ElevatedButton 吗?我已经查看了文档,但看不到任何明显的内容。
class IcoButton extends StatelessWidget {
IcoButton(
{@required this.lbl,
@required this.col,
@required this.ico,
@required this.onPress});
final String lbl;
final FaIcon ico;
final MaterialColor col;
final Function onPress;
@override
Widget build(BuildContext context) {
return ElevatedButton.icon(
label: Text(lbl),
icon: ico,
style: ElevatedButton.styleFrom(
primary: col,
onPrimary: Colors.white,
minimumSize: Size(160.0, 60.0),
textStyle: TextStyle(
fontSize: 24,
),
),
onPressed: onPress,
);
}
}
回答
将 null 传递给 onPressed 回调将禁用按钮。
If onPressed and onLongPress callbacks are null, then the button will be disabled.
https://api.flutter.dev/flutter/material/ElevatedButton-class.html