Skip to content

Commit 4492858

Browse files
authored
Merge pull request #1147 from cph-cachet/health-12/UV
[Health] Add iOS UV Index health data types
2 parents ab1945b + 08e11fc commit 4492858

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

packages/health/example/lib/main.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ class HealthAppState extends State<HealthApp> {
292292
value: 22,
293293
type: HealthDataType.LEAN_BODY_MASS,
294294
startTime: earlier,
295-
endTime: now,
296-
);
295+
endTime: now);
297296

298297
// specialized write methods
299298
success &= await health.writeBloodOxygen(
@@ -400,6 +399,12 @@ class HealthAppState extends State<HealthApp> {
400399
startTime: earlier,
401400
endTime: now,
402401
recordingMethod: RecordingMethod.manual);
402+
success &= await health.writeHealthData(
403+
value: 4.3,
404+
type: HealthDataType.UV_INDEX,
405+
startTime: earlier,
406+
endTime: now,
407+
recordingMethod: RecordingMethod.manual);
403408
}
404409

405410
setState(() {

packages/health/example/lib/util.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const List<HealthDataType> dataTypesIOS = [
6262
HealthDataType.MENSTRUATION_FLOW,
6363
HealthDataType.WATER_TEMPERATURE,
6464
HealthDataType.UNDERWATER_DEPTH,
65+
HealthDataType.UV_INDEX,
6566
];
6667

6768
/// List of data types available on Android.

packages/health/ios/Classes/SwiftHealthPlugin.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
164164
let MENSTRUATION_FLOW = "MENSTRUATION_FLOW"
165165
let WATER_TEMPERATURE = "WATER_TEMPERATURE"
166166
let UNDERWATER_DEPTH = "UNDERWATER_DEPTH"
167+
let UV_INDEX = "UV_INDEX"
167168

168169

169170
// Health Unit types
@@ -1670,6 +1671,10 @@ public class SwiftHealthPlugin: NSObject, FlutterPlugin {
16701671

16711672
dataTypesDict[WATER_TEMPERATURE] = HKQuantityType.quantityType(forIdentifier: .waterTemperature)!
16721673
dataTypesDict[UNDERWATER_DEPTH] = HKQuantityType.quantityType(forIdentifier: .underwaterDepth)!
1674+
1675+
dataTypesDict[UV_INDEX] = HKSampleType.quantityType(forIdentifier: .uvExposure)!
1676+
dataQuantityTypesDict[UV_INDEX] = HKQuantityType.quantityType(forIdentifier: .uvExposure)!
1677+
16731678
}
16741679

16751680
// Concatenate heart events, headache and health data types (both may be empty)

packages/health/lib/health.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/health/lib/src/heath_data_types.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum HealthDataType {
9191
HEADACHE_SEVERE,
9292
HEADACHE_UNSPECIFIED,
9393
NUTRITION,
94+
UV_INDEX,
9495
// HealthKit Characteristics
9596
GENDER,
9697
BIRTH_DATE,
@@ -212,6 +213,8 @@ const List<HealthDataType> dataTypeKeysIOS = [
212213
HealthDataType.MENSTRUATION_FLOW,
213214
HealthDataType.WATER_TEMPERATURE,
214215
HealthDataType.UNDERWATER_DEPTH,
216+
HealthDataType.UV_INDEX,
217+
HealthDataType.TOTAL_CALORIES_BURNED,
215218
];
216219

217220
/// List of data types available on Android
@@ -362,6 +365,7 @@ const Map<HealthDataType, HealthDataUnit> dataTypeToUnit = {
362365
HealthDataType.MENSTRUATION_FLOW: HealthDataUnit.NO_UNIT,
363366
HealthDataType.WATER_TEMPERATURE: HealthDataUnit.DEGREE_CELSIUS,
364367
HealthDataType.UNDERWATER_DEPTH: HealthDataUnit.METER,
368+
HealthDataType.UV_INDEX: HealthDataUnit.COUNT,
365369

366370
// Health Connect
367371
HealthDataType.TOTAL_CALORIES_BURNED: HealthDataUnit.KILOCALORIE,

0 commit comments

Comments
 (0)