How to Enable/Disable two Elevated Button in Flutter one after another?

Issue

I have two elevated buttons I want to disable if I click the A button and disable the B button if I click the B button then need to disable button A.

Solution

you can do it with just a single bool variable.

bool isAactive = true;

and code the buttons like

    ElevatedButton(
              onPressed: isAactive
                  ? () {
                      setState(() {
                        isAactive = false;
                      });
                    }
                  : null,
              child: Text('A')),
ElevatedButton(
              onPressed: !isAactive
                  ? () {
                      setState(() {
                        isAactive = true;
                      });
                    }
                  : null,
              child: Text('B')),

Answered By – Manish Dayma

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

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