Changed Graph Tooltip text
This commit is contained in:
@@ -46,6 +46,19 @@ class ReadingGraph extends StatelessWidget {
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
),
|
||||
lineTouchData: LineTouchData(
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((touchedSpot) {
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.y.toString()}\n${getLongDate(touchedSpot.x)}',
|
||||
TextStyle(
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.bold));
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -85,4 +98,18 @@ class ReadingGraph extends StatelessWidget {
|
||||
return hmFormat.format(
|
||||
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt()));
|
||||
}
|
||||
|
||||
String getLongDate(double value) {
|
||||
DateTime date =
|
||||
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt());
|
||||
int daysDifference = (DateTime.now().weekday - date.weekday + 7) % 7;
|
||||
|
||||
if (daysDifference == 0) {
|
||||
return 'Today ${intl.DateFormat('Hm').format(date)}';
|
||||
} else if (daysDifference == 1) {
|
||||
return 'Yesterday ${intl.DateFormat('Hm').format(date)}';
|
||||
}
|
||||
|
||||
return intl.DateFormat('yyyy-MM-dd H:m').format(date);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user