diff --git a/lib/features/measurements/widgets/categories_card.dart b/lib/features/measurements/widgets/categories_card.dart index 61b1db1c3..2b95b252d 100644 --- a/lib/features/measurements/widgets/categories_card.dart +++ b/lib/features/measurements/widgets/categories_card.dart @@ -132,14 +132,18 @@ class CategoriesCard extends StatelessWidget { /// are entered for all components at once. Widget _buildGroupCard(BuildContext context) { // Two components are one reading with a low and a high end, so they are - // drawn as a bar spanning it. More than two cannot be a range, they stay - // one line each. - final asRange = currentCategory.children.length == 2; - final ranges = asRange ? groupRangeEntries(currentCategory) : const []; + // drawn as a bar spanning it. Anything else stays one line per component: + // more than two components cannot be a range, and neither can readings + // that are not paired, which happens once the date of one half is edited + // apart from the other. + final ranges = currentCategory.children.length == 2 + ? groupRangeEntries(currentCategory) + : const []; + final asRange = ranges.isNotEmpty; final series = asRange ? const [] : groupComponentSeries(currentCategory); - final hasData = asRange ? ranges.isNotEmpty : series.any((s) => s.entries.isNotEmpty); + final hasData = asRange || series.any((s) => s.entries.isNotEmpty); return Card( elevation: elevation, diff --git a/test/features/measurements/widgets/categories_card_test.dart b/test/features/measurements/widgets/categories_card_test.dart index 297859890..92139719f 100644 --- a/test/features/measurements/widgets/categories_card_test.dart +++ b/test/features/measurements/widgets/categories_card_test.dart @@ -109,6 +109,28 @@ void main() { ); }); + testWidgets('falls back to lines when the readings are not paired', (tester) async { + // Editing the date of one half pulls a reading apart, and there is then + // no range to draw. The card must still show the data it has instead of + // going blank. + final sys = testMeasurementCategorySystolic.copyWith( + entries: [testNeasurementEntry9], + ); + final dia = testMeasurementCategoryDiastolic.copyWith( + entries: [ + testNeasurementEntry10.copyWith(date: DateTime(2026, 1, 1, 9, 30)), + ], + ); + final group = testMeasurementCategoryBloodPressure.copyWith(children: [sys, dia]); + + await tester.pumpWidget(_wrap(CategoriesCard(group))); + await tester.pumpAndSettle(); + + expect(find.byType(BarChart), findsNothing); + final data = tester.widget(find.byType(LineChart)).data; + expect(data.lineBarsData, hasLength(2)); + }); + testWidgets('renders no chart while no component has readings', (tester) async { await tester.pumpWidget(_wrap(CategoriesCard(_bpGroup(withEntries: false)))); await tester.pumpAndSettle();