title: How to use flutter provider in a statefulWidget?
body: <p>I am using flutter_provider for state management. I want to load some items on page(statefulwidget) load from Api. I am showing a loader on page start and want to show the items once they are fetched. </p>
  
  <p>PlayList.dart - </p>
  
  <pre><code>class Playlist extends StatefulWidget {
    @override
    _PlaylistState createState() =&gt; _PlaylistState();
  }
  
  class _PlaylistState extends State&lt;Playlist&gt; {
  var videosState;
    @override
    void initState() {
      super.initState();
       videosState = Provider.of&lt;VideosProvider&gt;(context);
      videosState.fetchVideosList();
    }
  
    @override
    Widget build(BuildContext context) {
      var videos = videosState.playlist;
      return Scaffold(
        appBar: AppBar(
          title: Text('My Videos'),
        ),
        body: RefreshIndicator(
          child: Container(
            width: double.infinity,
            height: double.infinity,
            child: videos.length
                ? ListView.builder(
                    itemBuilder: (BuildContext context, index) {
                      return _videoListItem(context, index, videos, videosState);
                    },
                    itemCount: videos.length,
                  )
                : Center(
                    child: CircularProgressIndicator(),
                  ),
          ),
          onRefresh: () =&gt; null,
        ),
      );
    }
  }
  </code></pre>
  
  <p>My provider is like this -</p>
  
  <pre><code>class VideosProvider with ChangeNotifier {
  
    List _playlist;
    int _currentVideoId;  
    get playlist =&gt; _playlist;
  
    void setPlayList(videosList) {
      _playlist = videosList;
    }
  
    Future fetchVideosList() async {
      http.Response response =
          await http.get("http://192.168.1.22:3000/videos-list/");
  
      print(json.decode(response.body));
      videos = json.decode(response.body)["data"];
      setPlayList(videos);
      return videos;
    }
  }
  </code></pre>
  
  <p>This gives an error of - </p>
  
  <pre><code>inheritFromWidgetOfExactType(_Provider&lt;VideosProvider&gt;) or inheritFromElement() was called before _PlaylistState.initState() completed.
  
  </code></pre>
  
  <p>here is the build method of the parent of playList class, wrapped in a changenotifier,</p>
  
  <pre><code>Widget build(BuildContext context) {
      return ChangeNotifierProvider&lt;VideosProvider&gt;(
        builder: (BuildContext context) =&gt; VideosProvider(),
        child: MaterialApp(
          title: "My App",
          home: new Playlist(),
        ),
      );
    }
  </code></pre>
  
  <p>So, all the examples on flutter_provider on internet show usage of provider on a statelesswidget, where state changes occur on user interactions like a button click. None about how to use provider in a statefulWidget, and cases where data has to be updated on page load without any interaction.</p>
  
  <p>I am aware of streambuilder and futurebuilder for this kind of scenarios, but want to understand how this can be done with flutter_provider. How can I use provider to call fetchVideosList in initState(on pageload)? Does this case can/should be handled with a statelessWidget?</p>