title: How should I go about updating a Stateless Widget when it's reloaded?
body: <p>I'm using a JSON file to store a list that I want to display and update. I have one StatefulWidget(called &quot;HOME&quot;) that shows the list using a ListView.builder. I also have a StatefulWidget(called &quot;ADD&quot;) that adds an object to the list and updates the JSON file. When I finish adding the list a Navigate back to &quot;HOME&quot;, I receive this error:
  <a href="https://i.stack.imgur.com/UsDg7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UsDg7.png" alt="Error Upon Returning to HOME" /></a></p>
  <p><a href="https://i.stack.imgur.com/NTtOO.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NTtOO.gif" alt="enter image description here" /></a>
  <br>
  HOME:</p>
  <pre><code>class Home extends StatefulWidget {
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  
  class _HomeState extends State&lt;Home&gt; {
  
    PlayerList playerList;
  
  
  
    @override
    void initState() {
      super.initState();
      readPlayerData().then((PlayerList list) {
        playerList = list;
      });
  
      
    }
  
    @override
    Widget build(BuildContext context) {
  
      // add Player to the PlayerList
      void addPlayer() async {
        await Navigator.pushReplacement(
          context,
          MaterialPageRoute(builder: (context) =&gt; AddPlayer()),
        );
  
        initState();
      }
  
      void removePlayer(int index) async {
  
        playerList.players.removeAt(index);
        await writePlayerData(playerList);
      }
  
      playerList = ModalRoute.of(context).settings.arguments;
  
      return Scaffold(
        backgroundColor: Colors.grey[900],
        appBar: AppBar(
          title: Text('Smash Tracker'),
          centerTitle: true,
          backgroundColor: Colors.grey[850],
          elevation: 0,
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {addPlayer();},
          child: Icon(Icons.add),
          backgroundColor: Colors.grey[600],
        ),
        body: Padding(
          padding: EdgeInsets.all(15.0),
          child: Container(
            child: Card(
              color: Colors.grey[900],
              shadowColor: Colors.black87,
              child: ListView.builder(
                itemCount: playerList.players.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    //leading: characterIcons(playerList.players[index]),
                    title: Text(
                      playerList.players[index].playerId,
                      style: TextStyle(
                        color: Colors.amberAccent,
                      ),
                    ),
                    subtitle: Text(
                      playerList.players[index].playerSetCount,
                      style: TextStyle(
                        color: Colors.amberAccent,
                      ),
                    ),
                    onTap: () {
                      Navigator.pushNamed(context, '/playerCard', arguments: {
                        'player': playerList.players[index],
                        'playerList': playerList,
                        'index': index
                      });
                    },
                    trailing: IconButton(
                      onPressed: () async {
                        removePlayer(index);
                        PlayerList newPlayerList = await readPlayerData();
                        setState(()  {
                          playerList = newPlayerList;
                        });
                        },
                      icon: Icon(Icons.delete_outline),
                      color: Colors.white,
                    ),
                  );
                },
              ),
            ),
          ),
        ),
      );
    }
  
  }
  </code></pre>
  <p>The code used to save a new Object when the 'Save' button is pressed<br>
  ADD:</p>
  <pre><code>  void _saveForm() async {
        
        PlayerList playerList = await readPlayerData();
  
        Player newPlayer = new Player(&quot;${playerName.trim()}&quot;, &quot;0 - 0&quot;,
            new Characters(_myChar1Result, _myChar2Result), &quot;&quot;);
        playerList.players.add(newPlayer);
  
        await writePlayerData(playerList);
  
        Navigator.pushReplacement(
          context,
          MaterialPageRoute(builder: (context) =&gt; Home()),
        );
    }
  </code></pre>
  <p>I think the error occurs when the ListView.builder attemps to call on the playerList object. I'm not sure. I'll be happy to provide any additional information.
  <br>
  'Edit:'Here is the readPlayerData() including the methods it relies on:</p>
  <pre><code>Future&lt;PlayerList&gt; readPlayerData () async {
    try {
      final file = await _localFile;
      String contents = await file.readAsString();
      final jsonResponse = (jsonDecode(contents)); //wrap in encode
      PlayerList playerList = PlayerList.fromJson(jsonResponse);
      return playerList;
    } catch (e) {
      print(e);
      return getPlayerList(); //just loads a placeholder json in the assets folder;
    }
  
  Future&lt;String&gt; get _localPath async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
  }
  
  Future&lt;File&gt; get _localFile async {
    final path = await _localPath;
    print(path);
    return File('$path/playerData.json');
  }
  </code></pre>
  <p>The json file saves the way I want it to.</p>