title: Flutter: How to rerun widget or build
body: <p>I am trying to create a quiz application and in my playQuiz, after the player has answered the correct answer then new answers would be generated. I have tried to make a function "foo" and call it so it would change the image and texts in the buttons. Still, nothing changes, this only changes when I rotate my screen. The code is short and easy to understand.</p>
  
  <pre><code>  class Game extends StatelessWidget {
    final ForceSelection forceSelection;
  
    Game({Key key, @required this.forceSelection}) : super(key: key);
  
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: forceSelection.langSelection, // TODO should work and change later
        theme: new ThemeData(
          primaryColor: Colors.white,
        ),
        home: PlayQuiz(),
      );
    }
  }
  
  class PlayQuizState extends State&lt;PlayQuiz&gt; {
    final ForceSelection forceSelection; // TODO Does this get forceSelection
  
    List&lt;String&gt; groundForce = [ 'sotamies', 'aliupseerioppilas', 'korpraali', 'alikersantti', 'upseerioppilas', 'kersantti', 'upseerikokelas', 'ylikersantti', 'vääpeli', 'ylivääpeli', 'sotilasmestari', 'vänrikki', 'luutnantti', 'yliluutnantti', 'kapteeni', 'majuri', 'everstiluutnantti', 'eversti', 'prikaatikenraali', 'kenraalimajuri', 'kenraaliluutnantti', 'kenraali'];
    List&lt;int&gt; randomList = Helper.randomAnswers();
    static var rng = new Random();
    var corrAnsIndex = rng.nextInt(3);
    int points = 0;
    String quizImage = "";
    String debugText = "";
  
    PlayQuizState(this.forceSelection); // TODO Does this get langSelection
  
  
    void _startGame() {
      quizImage = 'images/' + groundForce[randomList[corrAnsIndex]].replaceAll('ä','a') + '.jpg';
    }
    void _nextGame() {
      setState(() {
          points += 1;
          randomList = Helper.randomAnswers();
          corrAnsIndex = rng.nextInt(3);
          quizImage = 'images/' + groundForce[randomList[corrAnsIndex]].replaceAll('ä','a') + '.jpg';
          debugText = forceSelection.langSelection + randomList.toString() + " " + groundForce[randomList[corrAnsIndex]].replaceAll('ä','a');
          // TODO edited debug text and next is to check if langSelection is fin
      });
    }
    void _endGame() {
      setState(() {
        //TODO Ask for name and send to database
      });
    }
    @override
    Widget build(BuildContext context) {
  
      _startGame();
  
      return Scaffold(
        body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: &lt;Widget&gt;[
                Image.asset(quizImage),
                Text("randomList: " + randomList.toString()),
                Text("Oikea vastaus: " +
                    groundForce[randomList[corrAnsIndex]] +
                    " corrAnsIndex: " +
                    corrAnsIndex.toString()),
                Text(debugText + " points: " + points.toString()),
                //Text("Voima valinta: " + forceSelection = Game.forceSelection),
                RaisedButton(
                    child: Text(groundForce[randomList[0]]),
                    onPressed: () {
                      if (0 == corrAnsIndex) {
                        _nextGame();
                        //this.foo();
                      }
                    }),
                RaisedButton(
                    child: Text(groundForce[randomList[1]]),
                    onPressed: () {
                      if (1 == corrAnsIndex) {
                        _nextGame();
                      }
                    }),
                RaisedButton(
                    child: Text(groundForce[randomList[2]]),
                    onPressed: () {
                      if (2 == corrAnsIndex) {
                        _nextGame();
                      }
                    }),
                RaisedButton(
                    child: Text(groundForce[randomList[3]]),
                    onPressed: () {
                      if (3 == corrAnsIndex) {
                        _nextGame();
                      }
                    }),
              ],
            )),
      );
    }
  
  }
  
  
  class PlayQuiz extends StatefulWidget {
    @override
    PlayQuizState createState() =&gt; new PlayQuizState(ForceSelection("","")); //TODO how to pass vars to ""
  }
  </code></pre>