title: So what is the simplest approach for Caching in Flutter?
body: <p>The app is a simple news reader which shows WordPress posts, nothing fancy, not using a BLOC, inherited Widget, Firebase.
  I want it to show the cached data(which is the latest 10 posts) even when the user is offline.</p>
  
  <p>So if the user is offline show Cached data; or somehow default data is cached data.</p>
  
  <p>get the firstPost[Id] from WP REST API
  If the cached Json file contains Post[id] then show cached data;
  Else getPosts(); and show loading indicator. also please update the local JSON file. </p>
  
  <p>code to get JSON data: </p>
  
  <pre><code>// Function to fetch list of posts
   Future&lt;String&gt; getPosts() async {
   var res = await http
      .get(Uri.encodeFull(apiUrl + "posts?_embed&amp;per_page=10"), //TODO make it unlimited
          headers: {"Accept": "application/json"});
  
  setState(() {
    var resBody = json.decode(res.body);
  
    posts = resBody;
  });
  
  return "Success!";
  }
  </code></pre>
  
  <p>the future to get posts and shows loading indicator :</p>
  
  <pre><code>  body: FutureBuilder&lt;List&lt;String&gt;&gt;(
        future: getPosts(),
        builder: (context, snapshot) {
          if (snapshot.hasError) print(snapshot.error);
  
          return snapshot.hasData
              ? ListViewPosts(posts: snapshot.data)
              : Center(child: CircularProgressIndicator());
        },
      ),
  </code></pre>