For disabling any Button in flutter such as FlatButton
, RaisedButton
, MaterialButton
, IconButton
etc all you need to do is to set the onPressed
and onLongPress
properties to null. Below is some simple examples for some of the buttons:
FlatButton (Enabled)
FlatButton(
onPressed: (){},
onLongPress: null,
textColor: Colors.black,
disabledColor: Colors.orange,
disabledTextColor: Colors.white,
child: Text('Flat Button'),
),

FlatButton (Disabled)
FlatButton(
onPressed: null,
onLongPress: null,
textColor: Colors.black,
disabledColor: Colors.orange,
disabledTextColor: Colors.white,
child: Text('Flat Button'),
),

RaisedButton (Enabled)
RaisedButton(
onPressed: (){},
onLongPress: null,
color: Colors.lightBlueAccent,
textColor: Colors.black,
splashColor: Colors.blue,
elevation: 8.0,
disabledTextColor: Colors.white,
disabledColor: Colors.orange,
disabledElevation: 0.0,
child: Text('Raised Button'),
),

RaisedButton (Disabled)
RaisedButton(
onPressed: null,
onLongPress: null,
color: Colors.lightBlueAccent,
textColor: Colors.black,
splashColor: Colors.blue,
elevation: 8.0,
disabledTextColor: Colors.white,
disabledColor: Colors.orange,
disabledElevation: 0.0,
child: Text('Raised Button'),
),

IconButton (Enabled)
IconButton(
onPressed: () {},
icon: Icon(Icons.card_giftcard_rounded),
color: Colors.lightBlueAccent,
disabledColor: Colors.orange,
),

IconButton (Disabled)
IconButton(
onPressed: null,
icon: Icon(Icons.card_giftcard_rounded),
color: Colors.lightBlueAccent,
disabledColor: Colors.orange,
),

Note: Some of buttons such as IconButton
have only the onPressed
property.