title: How do I await end result of async chain from elsewhere in my code?
body: <p>Flutter newbie here. I'm trying to parse some json in dart and am getting confused with the async nature of reading the underlying file.</p>
  
  <p>How do I wait until the <em>json</em> has finished parsing and not just the underlying file? My confusion is that reading the file is asynchronous, but parsing the json is synchronous. Now I know that you can use await to wait for the Future to complete that's returned by loadString when reading the file. But how do I then "await" the completion of parsing the json?</p>
  
  <p>jsonDecode does not accept a Future as its arguments and it runs synchronously so I can't wrap it's results into a Future(or can I?). If I could somehow get a Future&lt; Map> _string2Item; as a result of the json parsing operation then that would solve my problem I think since I could simply: await _string2Item before doing anything.</p>
  
  <pre><code>class ItemsRepository
  {
   Map&lt;String, Item&gt; _string2Item;
  
    //This does not work unfortunately. However, I don't want to return an instance that hasn't finished parsing the json
    ItemsRepository() async
    {
      await init();
    }
  
    Future&lt;String&gt; _loadFile() async {
      return await rootBundle.loadString('assets/data/item_int2string.json');
    }
  
    Future&lt;void&gt; init() async
    {
      var _fileContents = _loadFile();
      _string2Item = jsonDecode(await _fileContents);
    }
  
    Item getItem(String id)
    {
      return _string2Item[id];
    }
  }
  
  //... somewhere else in my code
  ItemRepository ir = ItemRepository();
  ir.getItem("42"); //this crashes because _string2Item hasn't finished parsing yet.
  </code></pre>
  
  <p>Any help is appreciated.</p>