1717 */
1818
1919import 'package:health/health.dart' ;
20+ import 'package:wger/features/measurements/models/measurement_category.dart' ;
2021
2122/// A body metric that can be imported from Apple Health / Health Connect into a
2223/// measurement category.
2324///
24- /// [metricType] mirrors the server's planned `metric_type` enum and is stored
25- /// on the created category; it drives the mapping back to a category on the
26- /// next import.
25+ /// [metricType] is stored on the created category; it drives the mapping back
26+ /// to a category on the next import.
2727class HealthMetric {
2828 const HealthMetric ({
2929 required this .metricType,
@@ -35,15 +35,15 @@ class HealthMetric {
3535 this .disabledReason,
3636 });
3737
38- /// Value of the server `metric_type` enum , e.g. `body_fat` .
39- final String metricType;
38+ /// Metric type stored on the category , e.g. [MetricType.bodyFat] .
39+ final MetricType metricType;
4040
4141 /// Health platform type this metric reads.
4242 final HealthDataType dataType;
4343
4444 /// Stable, non-localized category name. Used to find-or-create the category,
45- /// and as the fallback match after a sync round-trip nulls [metricType]
46- /// (the server does not persist it yet ).
45+ /// and as the fallback match for a category the user already created by hand
46+ /// (which carries [MetricType.custom] , not this metric's type ).
4747 final String canonicalName;
4848
4949 /// Unit the value is stored in on the category.
@@ -79,23 +79,23 @@ double _identity(double raw) => raw;
7979/// its [HealthMetric.disabledReason] .
8080const List <HealthMetric > healthMetrics = [
8181 HealthMetric (
82- metricType: 'body_fat' ,
82+ metricType: MetricType .bodyFat ,
8383 dataType: HealthDataType .BODY_FAT_PERCENTAGE ,
8484 canonicalName: 'Body fat' ,
8585 unit: '%' ,
8686 toCategoryValue: _bodyFatToPercent,
8787 enabled: true ,
8888 ),
8989 HealthMetric (
90- metricType: ' height' ,
90+ metricType: MetricType . height,
9191 dataType: HealthDataType .HEIGHT ,
9292 canonicalName: 'Height' ,
9393 unit: 'cm' ,
9494 toCategoryValue: _heightToCm,
9595 enabled: true ,
9696 ),
9797 HealthMetric (
98- metricType: 'body_weight' ,
98+ metricType: MetricType .bodyWeight ,
9999 dataType: HealthDataType .WEIGHT ,
100100 canonicalName: 'Weight' ,
101101 unit: 'kg' ,
@@ -105,23 +105,23 @@ const List<HealthMetric> healthMetrics = [
105105 'weight/measurements merge (metric_type=body_weight).' ,
106106 ),
107107 HealthMetric (
108- metricType: 'blood_pressure' ,
108+ metricType: MetricType .bloodPressure ,
109109 dataType: HealthDataType .BLOOD_PRESSURE_SYSTOLIC ,
110110 canonicalName: 'Blood pressure' ,
111111 unit: 'mmHg' ,
112112 toCategoryValue: _identity,
113113 disabledReason: 'Needs measurement grouping to pair systolic/diastolic.' ,
114114 ),
115115 HealthMetric (
116- metricType: 'heart_rate' ,
116+ metricType: MetricType .heartRate ,
117117 dataType: HealthDataType .HEART_RATE ,
118118 canonicalName: 'Heart rate' ,
119119 unit: 'bpm' ,
120120 toCategoryValue: _identity,
121121 disabledReason: 'High-frequency; needs a per-day aggregation strategy.' ,
122122 ),
123123 HealthMetric (
124- metricType: ' steps' ,
124+ metricType: MetricType . steps,
125125 dataType: HealthDataType .STEPS ,
126126 canonicalName: 'Steps' ,
127127 unit: 'count' ,
0 commit comments