Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter – Unable to use setState() in TextButton

Why cannot I use setState in any of my buttons in flutter?
This is my code of the button:

TextButton(
                              style: TextButton.styleFrom(
                                fixedSize: Size(
                                    MediaQuery.of(context).size.width / 2, 100),
                              ),
                              onPressed: setState(() {
                                logPage = false;
                              }),
                              child: const Text(
                                "Sign Up",
                                style: TextStyle(fontSize: 20),
                              ),
                            )

but the setState command is underlined and Android Studio says:
This expression has a type of 'void' so its value can't be used.

I would like to change the variable and rebuild my app page to get it updated and it should show changes.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

onPressed: () => setState(() {
  logPage = false;
}),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading