0
votes

When i wanted to get my token i have this error : setState() callback argument returned a Future.

onPressed: () {
                    setState(() async {
                      if (_formKey.currentState.validate()) {
                        Candidate candidate = new Candidate(
                            lastname: lastname,
                            firstname: firstname,
                            email: email);
                        await candidate.candidateAuth(map: candidate.toMap());

                        Navigator.pushReplacement(
                            context,
                            MaterialPageRoute(
                                builder: (context) =>
                                    ThemePage(candidate: candidate)));
                      }
                    });
                  },

The problem, when i continue in my app, i have more problems threading.

1

1 Answers

3
votes

setState need to receive a pure function without side effects.

You can adjust that so you can call setState after the async function. Like this:

onPressed: () {

                      if (_formKey.currentState.validate()) {
                        Candidate candidate = new Candidate(
                            lastname: lastname,
                            firstname: firstname,
                            email: email);
                        await candidate.candidateAuth(map: candidate.toMap());

                        setState((){});

                        Navigator.pushReplacement(
                            context,
                            MaterialPageRoute(
                                builder: (context) =>
                                    ThemePage(candidate: candidate)));
                      }
                  },