0

At the beginning of my app I have a global variable gameData which is declared and instantiated as:

GameData gameData = GameData();

Later I want to clear the gameData variable and re-instantiate/reset the variable with a clean instance of GameData. I do this by calling a function:

void ResetGameData() {
  gameData = new GameData();
} 

But that's not clearing the gameData variable. All the old values are remaining. Is there a better way of doing this?

stfn3000
  • 193
  • 1
  • 1
  • 8

2 Answers2

0

It seems like your approach should work.

If you're building your UI based off of GameData, you will need to call setState() or notifyListeners() to rebuild everything.

Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
0

The issue was I was instantiating a class within a class, and that syntax was incorrect so the sub-class was retaining its previous data. The rest of the variable was re-instantiated correctly.

stfn3000
  • 193
  • 1
  • 1
  • 8