title: Flutter - Best approach to fetch data on init using provider
body: <p>I would like to know what's the best approach to fetch the data on a screen and also catch any error to show it with a dialog.</p>
  
  <p>This is my current approach at the moment.</p>
  
  <p>My provider:</p>
  
  <pre><code>Future&lt;People&gt; fetchPeople() async {
      final response = await http.get(url);
  
      if (response.statusCode == 200) {
        return People.fromJson(json.decode(response.body));
      } else {
        throw Exception('Failed loading people');
      }
    }
  </code></pre>
  
  <p>My home screen:</p>
  
  <pre><code>_fetchData() async {
      try {
        await Provider.of&lt;PeopleModel&gt;(context).fetchPeople();
      } catch (err) {
        // Show dialog
        print(err);
      }
    }
  
    @override
    void initState() {
      super.initState();
      _fetchData();
    }
  </code></pre>
  
  <p>I want to have my data available to use on init and also I want to show a dialog just in case there is an error.</p>
  
  <p>Thank you.</p>