title: Passing Data to a Stateful Widget in Flutter
body: <p>I'm wondering what the recommended way of passing data to a stateful widget, while creating it, is.</p>
  
  <p>The two styles I've seen are:</p>
  
  <pre><code>class ServerInfo extends StatefulWidget {
  
    Server _server;
  
    ServerInfo(Server server) {
      this._server = server;
    }
  
    @override
      State&lt;StatefulWidget&gt; createState() =&gt; new _ServerInfoState(_server);
  }
  
  class _ServerInfoState extends State&lt;ServerInfo&gt; {
    Server _server;
  
    _ServerInfoState(Server server) {
      this._server = server;
    }
  }
  </code></pre>
  
  <p>This method keeps a value both in <code>ServerInfo</code> and <code>_ServerInfoState</code>, which seems a bit wasteful.</p>
  
  <p>The other method is to use <code>widget._server</code>:</p>
  
  <pre><code>class ServerInfo extends StatefulWidget {
  
    Server _server;
  
    ServerInfo(Server server) {
      this._server = server;
    }
  
    @override
      State&lt;StatefulWidget&gt; createState() =&gt; new _ServerInfoState();
  }
  
  class _ServerInfoState extends State&lt;ServerInfo&gt; {
    @override
      Widget build(BuildContext context) {
        widget._server = "10"; // Do something we the server value
        return null;
      }
  }
  </code></pre>
  
  <p>This seems a bit backwards as the state is no longer stored in <code>_ServerInfoSate</code> but instead in the widget.</p>
  
  <p>Is there a best practice for this?</p>