title: Setting provider value in FutureBuilder
body: <p>I have a widget that makes a request to an api which returns a map. What I would like to do is not make the same request every time the widget is loaded and save the list to <code>appState.myList</code>. But. when I do this <code>appState.myList = snapshot.data;</code> in the <code>FutureBuilder</code>, I get the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>flutter: ══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
  flutter: The following assertion was thrown while dispatching notifications for MySchedule:
  flutter: setState() or markNeedsBuild() called during build.
  flutter: This ChangeNotifierProvider&lt;MySchedule&gt; widget cannot be marked as needing to build because the
  flutter: framework is already in the process of building widgets. A widget can be marked as needing to be
  flutter: built during the build phase only if one of its ancestors is currently building. ...
  </code></pre>
  
  <p><code>sun.dart</code> file:</p>
  
  <pre class="lang-dart prettyprint-override"><code>class Sun extends StatelessWidget {
    Widget build(BuildContext context) {
      final appState = Provider.of&lt;MySchedule&gt;(context);
      var db = PostDB();
  
      Widget listBuild(appState) {
        final list = appState.myList;
        return ListView.builder(
          itemCount: list.length,
          itemBuilder: (context, index) {
            return ListTile(title: Text(list[index].title));
          },
        );
      }
  
      Widget futureBuild(appState) {
        return FutureBuilder(
          future: db.getPosts(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData) {
              // appState.myList = snapshot.data;
              return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (context, index) {
                  return ListTile(title: Text(snapshot.data[index].title));
                },
              );
            } else if (snapshot.hasError) {
              return Text("${snapshot.error}");
            }
            return Center(
              child: CircularProgressIndicator(),
            );
          },
        );
      }
  
      return Scaffold(
          body: appState.myList != null
              ? listBuild(appState)
              : futureBuild(appState));
    }
  }
  </code></pre>
  
  <p><code>postService.dart</code> file:</p>
  
  <pre class="lang-dart prettyprint-override"><code>class PostDB {
    var isLoading = false;
  
    Future&lt;List&lt;Postmodel&gt;&gt; getPosts() async {
      isLoading = true;
      final response =
          await http.get("https://jsonplaceholder.typicode.com/posts");
  
      if (response.statusCode == 200) {
        isLoading = false;
        return (json.decode(response.body) as List)
            .map((data) =&gt; Postmodel.fromJson(data))
            .toList();
      } else {
        throw Exception('Failed to load posts');
      }
    }
  }
  </code></pre>
  
  <p>I understand that the <code>myList</code> calls <code>notifyListeners()</code> and that's what causes the error. Hope I got that right. If so, how do I set <code>appState.myList</code> and use in the app without getting the above error?</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/foundation.dart';
  import 'package:myflutter/models/post-model.dart';
  
  class MySchedule with ChangeNotifier {
    List&lt;Postmodel&gt; _myList;
  
    List&lt;Postmodel&gt; get myList =&gt; _myList;
  
    set myList(List&lt;Postmodel&gt; newValue) {
      _myList = newValue;
      notifyListeners();
    }
  }
  </code></pre>