harunB10
harunB10

Reputation: 5207

Flutter - DropdownButton onChanged does not call a function

I have a simple DropdownButton element and onChange event.

onChanged: (String newValue) {
    if (newValue == "Log out") {
        print("Inside IF");
        setState(){
            user.navigateToPreviousPage(Login(), context, false);
        }
    }
},

But from here I only get this print("Inside IF")... It does not call function which should remove user's token and navigate to login page. In addition, there are no errors or warnings...

What is wrong here? My whole class is Stateless Widget. Should I change it to Stateful?

Upvotes: 0

Views: 1011

Answers (1)

diegoveloper
diegoveloper

Reputation: 103451

You are calling setState in a wrong way:

setState(){
            user.navigateToPreviousPage(Login(), context, false);
        }

Correct way:

setState(() {
  user.navigateToPreviousPage(Login(), context, false);
});

And you should call Navigator.pop from the widget you want to dismiss :)

Upvotes: 1

Related Questions