Skip to content

Commit 91802cf

Browse files
authored
Fix inconsistent step of day interval (#46)
- In the badges a 24 hour interval is used, in the today screen a 0.00 until current time was used. - This caused some weird inconsistencies between the step amount of these two components - Because of that it was unified. This pull request includes a change to the `StatsViewModel` class in the `lib/presentation/today/view_model/stats_view_model.dart` file. The change updates the time interval used for fetching health statistics to cover the entire day from start to end. Time interval update: * [`lib/presentation/today/view_model/stats_view_model.dart`](diffhunk://#diff-3d33db26e691ac90dafcfa2cb8578bc15ae712031aa379f95c47e0acf4c5945cL18-R27): Changed the time interval variables from `lastMidnight` and `now` to `startOfDay` and `endOfDay` to ensure the entire day is covered when fetching steps and distance data.
2 parents b617120 + e05dc1c commit 91802cf

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/presentation/today/view_model/stats_view_model.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ class StatsViewModel extends StateNotifier<StatsState> {
1515

1616
Future<void> fetchStats() async {
1717
DateTime now = DateTime.now();
18-
var lastMidnight = DateTime(now.year, now.month, now.day);
18+
final startOfDay = DateTime(now.year, now.month, now.day);
19+
final endOfDay =
20+
startOfDay.add(const Duration(hours: 23, minutes: 59, seconds: 59));
1921
int steps = await ref
2022
.read(localHealthRepositoryProvider)
21-
.getStepsInInterval(lastMidnight, now);
23+
.getStepsInInterval(startOfDay, endOfDay);
2224
double distance = await ref
2325
.read(localHealthRepositoryProvider)
2426
.getDistanceInInterval(
25-
lastMidnight, now) / 1000;
27+
startOfDay, endOfDay) / 1000;
2628
int sleep = await ref
2729
.read(localHealthRepositoryProvider)
2830
.getSleepFromDate(now.subtract(const Duration(days: 1)));

0 commit comments

Comments
 (0)