getHeartBeatsForRange method
Gets the heartbeats for the range between initialDate
and
finalDate
Implementation
Future<List<Heartbeat>> getHeartBeatsForRange(
DateTime initialDate,
DateTime finalDate,
) async {
assert(initialDate.isBefore(finalDate));
final dates = List.generate(
initialDate.difference(finalDate).inDays.abs() + 1,
(index) => initialDate.add(Duration(days: index)),
);
final heartbeats = <Heartbeat>[];
await for (final date in Stream.fromIterable(dates)) {
heartbeats.addAll(await getHeartbeats(date));
}
heartbeats.sort(
(h1, h2) =>
DateTime.parse(h1.createdAt).compareTo(DateTime.parse(h2.createdAt)),
);
return heartbeats;
}