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.
>Solution :
Try this:
onPressed: () => setState(() {
logPage = false;
}),