getStoriesToday method

Future<List<StoryModel>> getStoriesToday()

Implementation

Future<List<StoryModel>> getStoriesToday() {
  return _httpService.getAllStories().then((data) async {
    if (data.statusCode == 200) {
      List<dynamic> story = json.decode(data.body);
      List<StoryModel> storiesList =
          story.map((i) => StoryModel.fromJson(i)).toList();
      final date = DateTime.now();
      List<StoryModel> storyToday = storiesList
          .where((s) => date.difference(s.createdAt!).inDays < 1)
          .toList();
      return storyToday;
    } else {
      return List<StoryModel>.from([]);
    }
  });
}