How do I disable a Button in Flutter?

I’m just starting to get the hang of Flutter, but I’m having trouble figuring out how to set the enabled state of a button.

From the docs, it says to set onPressed to null to disable a button, and give it a value to enable it. This is fine if the button continues to be in the same state for the lifecycle.

I get the impression I need to create a custom Stateful widget that will allow me to update the button’s enabled state (or onPressed callback) somehow.

So my question is how would I do that? This seems like a pretty straightforward requirement, but I can’t find anything in the docs on how to do it.

Thanks.

15 Answers
15

Leave a Comment