A2oz

How do you make an elevated button Unclickable in Flutter?

Published in Flutter Development 1 min read

You can make an elevated button unclickable in Flutter by setting its onPressed property to null.

Here's how you can do it:

ElevatedButton(
  onPressed: null, // Set onPressed to null to make it unclickable
  child: Text('Unclickable Button'),
)

This will create an elevated button that appears visually the same as a clickable button, but it won't respond to any user interaction.

Alternatively, you can use the enabled property of the ElevatedButton widget:

ElevatedButton(
  onPressed: () {
    // Button functionality
  },
  child: Text('Clickable Button'),
  enabled: false, // Set enabled to false to make it unclickable
)

This will disable the button, making it appear visually grayed out and unresponsive to user interaction.

Practical Insights:

  • Disabling a button can improve user experience by preventing unintended actions.
  • It can also be used to indicate that a particular action is unavailable or in progress.
  • Use onPressed: null if you want to visually maintain the button but make it unclickable.
  • Use enabled: false if you want the button to appear visually disabled.

Related Articles