loadPosts method

Future<List<PostModel>> loadPosts()

Implementation

Future<List<PostModel>> loadPosts() {
  return _httpService.fetchAllPosts().then((data) async {
    if (data.statusCode == 200) {
      List<dynamic> posts = json.decode(data.body);
      List<PostModel> postsList =
          posts.map((i) => PostModel.fromJson(i)).toList();
      return postsList;
    } else {
      return List<PostModel>.from([]);
    }
  });
}