title: setState not reloading state in Dart / Flutter?
body: <p>I followed the Flutter tutorial from Google CodeLabs -</p>
  
  <p><a href="https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1" rel="nofollow noreferrer">Part 1</a></p>
  
  <p><a href="https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2" rel="nofollow noreferrer">Part 2</a></p>
  
  <p>Then I tried adding <a href="https://pub.dartlang.org/packages/shared_preferences" rel="nofollow noreferrer">SharedPreferences</a> to persist data. Saving data works perfectly but deleting doesn't.</p>
  
  <p>My complete code is available at <a href="https://github.com/deadcoder0904/flutter-startup-name-generator/" rel="nofollow noreferrer">https://github.com/deadcoder0904/flutter-startup-name-generator/</a></p>
  
  <h1>Screen 1 (Lists all startup names)</h1>
  
  <p><img src="https://i.stack.imgur.com/ogMwU.png" width="400" height="750" alt="flutter_heart" /></p>
  
  <h1>Screen 2 (All saved startup names from Screen 1 show here)</h1>
  
  <p><img src="https://i.stack.imgur.com/uMPfg.png" width="400" height="750" alt="flutter_trash" /></p>
  
  <p>On <code>Screen 2</code>, deleting a startup name by clicking on trash icon doesn't remove the data instantly. I have to traverse to <code>Screen 1</code> &amp; back again at <code>Screen 2</code> to see the item being removed.</p>
  
  <p>The error is in <code>setState</code> below or you can also view it <a href="https://github.com/deadcoder0904/flutter-startup-name-generator/blob/master/lib/main.dart#L117-L121" rel="nofollow noreferrer">on Github</a> with nice formatting</p>
  
  <pre><code>void _pushSaved() {
      Navigator.of(context).push(
          MaterialPageRoute&lt;void&gt;(
              builder: (BuildContext context) {
                  final Iterable&lt;ListTile&gt; tiles = _saved.map(
                      (String word) {
                          return ListTile(
                              title: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: &lt;Widget&gt;[
                                      Text(
                                          word,
                                          style: _biggerFont,
                                      ),
                                      IconButton(
                                          icon: const Icon(Icons.delete),
                                          onPressed: () {
                                              setState(() {
                                                  _saved.remove(word);
                                                  savePrefs(_saved);
                                              });
                                          },
                                      )
                                  ],
                              ),
                          );
                      },
                  );
  
                  final List&lt;Widget&gt; divided = ListTile.divideTiles(
                      context: context,
                      tiles: tiles,
                  ).toList();
  
                  return Scaffold(
                      appBar: AppBar(
                          title: const Text('Saved Suggestions'),
                      ),
                      body: ListView(children: divided),
                  );
              },
          ),
      );
  }
  </code></pre>
  
  <p><code>_saved.remove(word);</code> inside <code>setState</code> doesn't remove the startup name instantly. </p>
  
  <p>Should I make another stateful component? How do I solve it?</p>