Some improvements to interval handling

This commit is contained in:
Roland Geider
2023-11-05 14:52:35 +01:00
parent 005f4d3db7
commit 67f727867c
3 changed files with 11 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
double chartGetInterval(DateTime first, DateTime last, {divider: 3}) {
double chartGetInterval(DateTime first, DateTime last, {divider = 3}) {
final dayDiff = last.difference(first);
return dayDiff.inMilliseconds.toDouble() / 3;
return dayDiff.inMilliseconds == 0 ? 1000 : dayDiff.inMilliseconds.abs() / divider;
}

View File

@@ -93,7 +93,9 @@ class _MeasurementChartWidgetFlState extends State<MeasurementChartWidgetFl> {
DateFormat.yMd(Localizations.localeOf(context).languageCode).format(date),
);
},
interval: chartGetInterval(widget._entries.last.date, widget._entries.first.date),
interval: widget._entries.isNotEmpty
? chartGetInterval(widget._entries.last.date, widget._entries.first.date)
: 1000,
),
),
leftTitles: AxisTitles(

View File

@@ -73,8 +73,8 @@ void main() {
expect(find.text('body fat'), findsOneWidget);
// Entries
expect(find.text('10.2 %'), findsOneWidget);
expect(find.text('18.1 %'), findsOneWidget);
expect(find.text('10.2 %'), findsNWidgets(2));
expect(find.text('18.1 %'), findsNWidgets(2));
});
testWidgets('Tests the localization of dates - EN', (WidgetTester tester) async {
@@ -83,8 +83,8 @@ void main() {
await tester.pumpAndSettle();
// From the entries list and from the chart
expect(find.text('8/1/2021'), findsNWidgets(3));
expect(find.text('8/10/2021'), findsNWidgets(2));
expect(find.text('8/1/2021'), findsNWidgets(2));
expect(find.text('8/10/2021'), findsOneWidget);
});
testWidgets('Tests the localization of dates - DE', (WidgetTester tester) async {
@@ -92,7 +92,7 @@ void main() {
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(find.text('1.8.2021'), findsOneWidget);
expect(find.text('1.8.2021'), findsNWidgets(2));
expect(find.text('10.8.2021'), findsOneWidget);
});
}