Commit 21405b4

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-06-25 16:50:44
fix legacy list
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent 12fdd3b
Changed files (4)
app/lib/components/measurement_list/measurement_list_entry.dart
@@ -1,5 +1,6 @@
 import 'package:blood_pressure_app/components/dialoges/confirm_deletion_dialoge.dart';
-import 'package:blood_pressure_app/model/blood_pressure/pressure_unit.dart';
+import 'package:blood_pressure_app/components/nullable_text.dart';
+import 'package:blood_pressure_app/components/pressure_text.dart';
 import 'package:blood_pressure_app/model/storage/storage.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_bloc/flutter_bloc.dart';
@@ -91,33 +92,26 @@ class MeasurementListRow extends StatelessWidget {
     );
   }
 
-  Row _buildRow(DateFormat formatter) {
-    String formatNum(num? num) => (num ?? '-').toString();
-    String formatPressure(Pressure? num) => switch(settings.preferredPressureUnit) {
-      PressureUnit.mmHg => formatNum(num?.mmHg),
-      PressureUnit.kPa => formatNum(num?.kPa),
-    };
-    return Row(
-      children: [
-        Expanded(
-          flex: 30,
-          child: Text(formatPressure(data.sys)),
-        ),
-        Expanded(
-          flex: 30,
-          child: Text(formatPressure(data.dia)),
-        ),
-        Expanded(
-          flex: 30,
-          child: Text(formatNum(data.pul)),
-        ),
-        Expanded(
-          flex: 10,
-          child: data.$3.isNotEmpty ? Icon(Icons.medication) : SizedBox.shrink(),
-        ),
-      ],
-    );
-  }
+  Row _buildRow(DateFormat formatter) => Row(
+    children: [
+      Expanded(
+        flex: 30,
+        child: PressureText(data.sys),
+      ),
+      Expanded(
+        flex: 30,
+        child: PressureText(data.dia),
+      ),
+      Expanded(
+        flex: 30,
+        child: NullableText((data.pul?.toString())),
+      ),
+      Expanded(
+        flex: 10,
+        child: data.$3.isNotEmpty ? Icon(Icons.medication) : SizedBox.shrink(),
+      ),
+    ],
+  );
 
   void _deleteEntry(Settings settings, BuildContext context, AppLocalizations localizations) async {
     final bpRepo = RepositoryProvider.of<BloodPressureRepository>(context); // TODO: extract
app/lib/components/nullable_text.dart
@@ -0,0 +1,13 @@
+import 'package:flutter/material.dart';
+
+/// A text widget that shows a placeholder('-') when no text is present.
+class NullableText extends StatelessWidget {
+  /// Show text or a placeholder
+  const NullableText(this.text, {super.key});
+
+  /// Text to display.
+  final String? text;
+
+  @override
+  Widget build(BuildContext context) => Text(text ?? '-');
+}
app/lib/components/pressure_text.dart
@@ -0,0 +1,25 @@
+import 'package:blood_pressure_app/components/nullable_text.dart';
+import 'package:blood_pressure_app/model/blood_pressure/pressure_unit.dart';
+import 'package:blood_pressure_app/model/storage/settings_store.dart';
+import 'package:flutter/material.dart';
+import 'package:health_data_store/health_data_store.dart';
+import 'package:provider/provider.dart';
+
+/// A display [pressure] in the correct [Settings.preferredPressureUnit].
+class PressureText extends StatelessWidget {
+  /// Display a [pressure] in the correct [Settings.preferredPressureUnit].
+  const PressureText(this.pressure, {super.key});
+
+  /// Pressure to display.
+  ///
+  /// When this is null a placeholder '-' is displayed.
+  final Pressure? pressure;
+
+  @override
+  Widget build(BuildContext context) => NullableText(
+    switch (context.watch<Settings>().preferredPressureUnit) {
+      PressureUnit.mmHg => pressure?.mmHg,
+      PressureUnit.kPa => pressure?.kPa,
+    }.toString(),
+  );
+}
app/lib/screens/elements/legacy_measurement_list.dart
@@ -2,6 +2,7 @@ import 'dart:collection';
 
 import 'package:blood_pressure_app/components/dialoges/add_measurement_dialoge.dart';
 import 'package:blood_pressure_app/components/dialoges/confirm_deletion_dialoge.dart';
+import 'package:blood_pressure_app/components/nullable_text.dart';
 import 'package:blood_pressure_app/model/storage/intervall_store.dart';
 import 'package:blood_pressure_app/model/storage/settings_store.dart';
 import 'package:blood_pressure_app/screens/elements/blood_pressure_builder.dart';
@@ -12,6 +13,8 @@ import 'package:health_data_store/health_data_store.dart';
 import 'package:intl/intl.dart';
 import 'package:provider/provider.dart';
 
+import '../../components/pressure_text.dart';
+
 /// A old more compact [BloodPressureRecord] list, that lacks some of the new
 /// features.
 class LegacyMeasurementsList extends StatelessWidget {
@@ -132,14 +135,13 @@ class LegacyMeasurementsList extends StatelessWidget {
                               child: Text(formatter.format(records[index].time)),),
                             Expanded(
                               flex: _tableElementsSizes[1],
-                              // FIXME: "Instance of Pressure"
-                              child: Text((records[index].sys ?? '').toString()),),
+                              child: PressureText(records[index].sys)),
                             Expanded(
                               flex: _tableElementsSizes[2],
-                              child: Text((records[index].dia ?? '').toString()),),
+                              child: PressureText(records[index].dia),),
                             Expanded(
                               flex: _tableElementsSizes[3],
-                              child: Text((records[index].pul ?? '').toString()),),
+                              child: NullableText(records[index].pul?.toString()),),
                             // FIXME: reimplement notes
                             /*Expanded(
                                   flex: _tableElementsSizes[4],