title: Flutter Init State Called Multiple Times
body: <p>Every time I navigate away from a widget, and then come back to it, I get a "n+1" call to the <code>initState</code> method of that widget. </p>
  
  <p>The setup I have is something similar to this. I start at widget A, when a click on a Card is recognized, we do <code>Navigator.pushNamed(B.routeName)</code> to display the detail screen for this item. Once there is some additional processing done, the user clicks a "submit" button on B, and returns to a with <code>Navigator.pushNamed(A.routeName)</code>.</p>
  
  <pre><code>class A extends StatefulWidget {
  
    static String routeName = 'aroutename';
    A({Key key}) : super(key: key);
  
    _AState createState() =&gt; _AState();
  }
  
  class _AState extends State&lt;A&gt; {
  
    @override
    void initState() {
      super.initState();
      getSomeDataForScreenA().then((result) =&gt; setState(...));
    }
  
    whenDone(){
  
      Navigator.of(context).pushNamed(B.routeName);
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
  
      );
    }
  }
  
  class B extends StatefulWidget {
    B({Key key}) : super(key: key);
  
    _BState createState() =&gt; _BState();
  }
  
  class _BState extends State&lt;B&gt; {
  
    static String routeName = 'broutename';
  
    @override
    void initState() {
      super.initState();
      getSomeDataForScreenB().then((result) =&gt; setState(...));
    }
  
    whenDone(){
      Navigator.of(context).pushNamed(A.routeName);
    }
  
    @override
    Widget build(BuildContext context) {
      return Container(
  
      );
    }
  }
  </code></pre>
  
  <p>The first time we see A, it's fine it only runs once. Then we go to B, and then once we return to A, initState() is called twice. The third time we make this cycle, it's called 3 times, etc...</p>
  
  <p>Hopefully someone can point me in the right direction here as to what i am doing wrong. I am aware that this is probably due to a lack of understanding of the <code>Navigator.of(context)</code> inner workings, but I can't seem to find the answer anywhere.</p>