londonappbrewery / quizzler-flutter

Learn to Code While Building Apps - The Complete Flutter Development Bootcamp
https://www.appbrewery.co
196 stars 870 forks source link

is it setState issue or is it correct ? #4

Open himanshu-neutrorion opened 4 years ago

himanshu-neutrorion commented 4 years ago

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 commented 4 years ago

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, ), ); }); }, ), ), ),