Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it setState issue or is it correct ? #4

Open
himanshu-neutrorion opened this issue Apr 18, 2020 · 1 comment
Open

is it setState issue or is it correct ? #4

himanshu-neutrorion opened this issue Apr 18, 2020 · 1 comment

Comments

@himanshu-neutrorion
Copy link

The below code also works very well. See the last line where setState does not have anything inside it, but everything is outside it. Still everything works.

void checkAnswer(bool userPickerAnswer) {
    bool correctAnswer = quizBrain.getQuestionAnswer();
    if (userPickerAnswer == correctAnswer) {
      scoreKeeper.add(Icon(
        Icons.check,
        color: Colors.green,
      ));
      print('user got it right');
    } else {
      scoreKeeper.add(Icon(
        Icons.close,
        color: Colors.red,
      ));
      print('user got it wrong');
    }
    quizBrain.nextQuestion();
    setState(() {});
  }
@najib-mrh
Copy link

Same here, the SetState doesn't work for me ... i don't know why

Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
child: FlatButton(
textColor: Colors.white,
color: Colors.green,
child: Text(
'True',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
onPressed: () {
//The user picked true.
setState(() {
scoreKeeper.add( new
Icon(
Icons.check,
color: Colors.green,
),
);
});
},
),
),
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants