title: Invalid arguments: The source must not be null
body: <p>I had this app that fetches some data from a remote API. So the data that I am going to receive and display in a JSON <code>Future</code>:
  <code>
  {"status":200,"out":{"summary":[{"bc":"1876","wc":"488679","pc":"731904"}],"last":[{"id":"1877","place":"7","publisher":"-1","bookid":"01877","title":"Neither Civil Nor Servant","author":"Peh","region":"\u65b0\u52a0\u5761","copyrighter":"","translated":"0","purchdate":"2017-04-18","price":"200.00","pubdate":"2016-01-01","printdate":"2016-01-01","ver":"1.1","deco":"\u666e\u901a","kword":"0","page":"220","isbn":"978-981-4642-63-7","category":"","location":"","intro":"TT\u8d60\u4e66\u3002","instock":"1","p_name":"\uff08\u672a\u6307\u5b9a\uff09"}]}}
  </code></p>
  
  <p>I will extract the <code>out</code> field from this JSON and assing <code>summary</code> and <code>last</code> to two variables:</p>
  
  <pre><code>initState() async {
      var getter = createHttpClient();
      String uri='http://api.rsywx.com/book/summary';
      var res=await getter.get(uri);
      Map data=JSON.decode(res.body);
  
      var out=data['out'];
  
      setState(() {
        _today=formatDate(new DateTime.now());
        _lb=out['last'][0];
        _bs=out['summary'][0];
        _lb['purchdate']=formatDate(DateTime.parse(_lb['purchdate']));
      });
    }
  </code></pre>
  
  <p>So <code>_bs</code> and <code>_lb</code> are all compound objects. </p>
  
  <p>In my widget <code>build</code> function, I will display the contents of these two objects:</p>
  
  <pre><code> new TextSpan(
       text: numFormatter.format(int.parse(_bs['bc'])),
       style: aboutTextStyle,
   ),
  </code></pre>
  
  <p>The program compiles OK but when launched, a quick splash RED screen will appear:</p>
  
  <p><a href="https://i.stack.imgur.com/K8kBA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K8kBA.png" alt="enter image description here"></a></p>
  
  <p>And soon enough, the correct screen will appear:<a href="https://i.stack.imgur.com/IQOLt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IQOLt.png" alt="enter image description here"></a></p>
  
  <p>I know that during the initial <code>build</code>, the object <code>_bs</code>, <code>_lb</code> is not there yet and the async call to a remote API is still trying to populate the returned response, so in this case, <code>_bs['bc']</code> will definitely be not callable. Thus the non-blocking error pops out. </p>
  
  <p><strong>Workaround</strong></p>
  
  <p>I can eliminate this error by declaring a bunch of variables and assign them in the <code>initState</code> function; instead of rendering <code>_bs['bc']</code>, I will render a new variable <code>_bookCoount</code>. This way, the rendering will be done without this RED screen and the value of that variable will initially be <code>null</code> and soon be the correct value fetched from remote API. </p>
  
  <p>But this is too cumbersome, if you get what I mean: A lot of used-only-once variables. </p>
  
  <p>Or, shall I make the data fetched on the parent level, so that it will be passed to this widget as props? Not tried yet. </p>
  
  <p>Would appreciate your best practice input. </p>
  
  <p><strong>Update</strong></p>
  
  <p>The issue really comes from <code>int.parse</code>. If I took out that call, the program runs peacefully. </p>
  
  <p>So the question now becomes</p>
  
  <p>I would suppress <code>int.parse</code> prompting an error before the value it is going to parse becomes valid. </p>