title: Global variables or Provider not allowing incrementation in Flutter
body: <p>Global variables or Provider, won't allow me to increment the round number or the current player number.</p>
  <p>I'm trying to cycle through rounds in a game, and for each round all the players should play one by one.
  I have the players in a PlayerData Provider. Also there I've put currentPlayerNumber and currentRoundNumber.</p>
  <p>I'm taking the totalRoundNumber from the previous page, passed in the constructor of the current page.</p>
  <pre><code>MaterialButton(
                    onPressed: () {
                      //if current round is less than the entire number of rounds then play
                      if (Provider.of&lt;PlayerData&gt;(context).currentRoundNumber &lt; widget.totalRoundNumber) {
                        //if current player number is less than the total of players
                        if (Provider.of&lt;PlayerData&gt;(context).currentRoundNumber&lt;
                            Provider.of&lt;PlayerData&gt;(context).playerCount) {
                          //go to the voting page to select yes/no
                          Navigator.pushNamed(context, '/voting');
                        }
                        //if current player number is equal to the total # of players (all the players have played)
                        if (Provider.of&lt;PlayerData&gt;(context)
                                .currentPlayerNumber ==
                            Provider.of&lt;PlayerData&gt;(context).playerCount) {
                          //increase current round number and pass to next round
                          Provider.of&lt;PlayerData&gt;(context).incrementCurrentRoundNumber();
                          //set currentplayer number to 0 and the players start over to the next round
                          Provider.of&lt;PlayerData&gt;(context)
                              .resetCurrentPlayerNumber();
                        }
                        // } else {
                        //   //TODO go to the results page and pass the results
                        // }
                      }
                    },
  </code></pre>
  <p>in the voting page I have the following:</p>
  <pre><code>child: MaterialButton(
              //if the player managed to succeed the challenge
              child: Text('He did it!'),
              onPressed: () {
                //increase the score of the player
                //setPlayerScore(playerNumber) function increases the score by 1
                Provider.of&lt;PlayerData&gt;(context)
                    .setPlayerScore(
                  //this is the current player number, for which the score is to be increased
                  //also taken from the PlayerData
                    Provider.of&lt;PlayerData&gt;(context).currentPlayerNumber);
                 //this is a void method, that increases the currentPlayerNumber by 1
                Provider.of&lt;PlayerData&gt;(context).incrementCurrentPlayerNumber();
                //navigate back to the previous page
                Navigator.pushNamed(context, '/questions');
              },
            ),
  </code></pre>
  <p>It works incrementing once the current player number and then I get:</p>
  <pre><code>The method '&gt;' was called on null.
  Receiver: null
  Tried calling: &gt;(1)
  </code></pre>
  <p>I tried:</p>
  <ul>
  <li>global variables for the currentPlayerNumber and currentRound number</li>
  <li>building a separate Provider just for these two variables</li>
  </ul>
  <p>I really can't think of another solution...</p>
  <p>Player data file:</p>
  <pre><code>class PlayerData extends ChangeNotifier {
  List&lt;Player&gt; _players = [];
  Game _game = Game(currentRoundNumber: 1,currentPlayerNumber: 0);
  
  UnmodifiableListView&lt;Player&gt; get players {
  return UnmodifiableListView(_players);
  </code></pre>
  <p>}</p>
  <pre><code>int get currentRoundNumber{
    return _game.currentRoundNumber;
  </code></pre>
  <p>}</p>
  <pre><code>int get currentPlayerNumber{
    return _game.currentPlayerNumber;
  }
  
  void resetCurrentPlayerNumber (){
  _game.currentPlayerNumber =0;
  }
  
  void incrementCurrentPlayerNumber() {
    _game.currentPlayerNumber ++;
  }
  
  void incrementCurrentRoundNumber(){
    _game.currentRoundNumber++;
  }
  
  void resetCurrentRoundNumber(){
    _game.currentRoundNumber = 0;
  }
  
  
  int get playerCount {
  print('player count: ${_players.length}');
      return _players.length;
  </code></pre>
  <p>}</p>
  <pre><code>void addPlayer(String newPlayerName) {
  if (_players.length &lt; 8) {
    _players.add(Player(name: newPlayerName,score: 0));
    notifyListeners();
  }
  </code></pre>
  <p>}</p>
  <pre><code>void deletePlayer(Player player) {
  _players.remove(player);
  notifyListeners();
  </code></pre>
  <p>}</p>
  <pre><code>void resetPlayerScore(Player player) {
  player.resetScore();
  notifyListeners();
  </code></pre>
  <p>}</p>
  <pre><code>Player getPlayer(int i) {
  print(i);
  if (i &lt; _players.length) {
    return _players[i];
  } else
    return null;
  </code></pre>
  <p>}</p>
  <pre><code>void setPlayerScore(int playerNumber) {
  _players[playerNumber].score++;
  notifyListeners();
  </code></pre>
  <p>}</p>
  <pre><code>void updatePlayer(Player player) {
  notifyListeners();
  </code></pre>
  <p>}
  }</p>