How to disable a button in Flutter.

To disable a Button in Flutter, we can simply give the onpressed: parameter a null value. This will disable the button. Something like this will work:-

      onPressed: null,
      child: Text('Button disabled')

But our button will be of no use like this. Instead, a better approach is to create a helper function that returns true/false based on the conditions and enables/disables the button accordingly. For example, pushing a button once to log in and then the button gets disabled. Code would be somewhat like this:-

      onPressed: HelperFunctionToToggleButton() ? null : 
      child: Text('Button disabled/enabled')

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.