Skip to content

Commit 318cd86

Browse files
committed
The empty week statistics graph is fixed and weekly hydration percent is fixed
1 parent 8c06ca6 commit 318cd86

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/models/weekly_data.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '../utils/get_week.dart';
2+
13
class WeeklyData {
24
String id;
35
int year;
@@ -47,8 +49,15 @@ class WeeklyData {
4749
}
4850

4951
int percentThisWeek(){
52+
DateTime today = DateTime.now();
53+
int thisWeek = getWeek(today);
54+
double max;
55+
if(thisWeek==this.week && today.year==this.year){
56+
max = (dailyTarget*DateTime.now().weekday).toDouble();
57+
}else{
58+
max = (dailyTarget*7).toDouble();
59+
}
5060
double total = totalThisWeek();
51-
double max = (dailyTarget*DateTime.now().weekday).toDouble();
5261
return ((total/max)*100).toInt();
5362
}
5463
}

lib/widgets/weekly_statistics_graph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WeeklyStatisticsGraph extends StatelessWidget {
2525
}
2626
}
2727
for(int i=1;i<=7;i++){
28-
double h = maxH*(intakes[i.toString()]/max);
28+
double h = max==0 ? 0 : maxH*(intakes[i.toString()]/max);
2929
bars.add(
3030
Column(
3131
mainAxisSize: MainAxisSize.min,

0 commit comments

Comments
 (0)