Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Enable/Disable an ElevatedButton in Flutter

Tags:

flutter

Does anybody know how to enable/disable a Flutter ElevatedButton? I've reviewed the documentation but I can't see anything that is obvious.

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,
    );
     }
    }
like image 417
Adrian Smith Avatar asked Nov 24 '25 23:11

Adrian Smith


1 Answers

Passing null to the onPressed callback will disable the button.

If onPressed and onLongPress callbacks are null, then the button will be disabled.

https://api.flutter.dev/flutter/material/ElevatedButton-class.html

like image 155
Shannon Avatar answered Nov 26 '25 17:11

Shannon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!