mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Some improvements to interval handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user