mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-03 10:33:54 +01:00
Keep the group card readable when readings are not paired
This commit is contained in:
@@ -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 <MeasurementChartEntry>[];
|
||||
// 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 <MeasurementChartEntry>[];
|
||||
final asRange = ranges.isNotEmpty;
|
||||
final series = asRange
|
||||
? const <MeasurementChartSeries>[]
|
||||
: 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,
|
||||
|
||||
@@ -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<LineChart>(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();
|
||||
|
||||
Reference in New Issue
Block a user