HealthKitReporter class

HealthKitReporter class. Invokes calls to native side. Channel: health_kit_reporter_method_channel For reading data, all responses are provided as JSON based payloads.

The list of Platform methods:

Functions enableBackgroundDelivery, disableAllBackgroundDelivery, disableBackgroundDelivery are preferred to use with observerQuery set up, since they allow background notifications when data in HealthKit changes. This combination will wake up your App in background and perform actions you specify when any data changes in HealthKit depending on the provided UpdateFrequency. See enableBackgroundDelivery.

See more about observer queries in https://developer.apple.com/documentation/healthkit/hkobserverquery

Every call to HealthKit with a read request should be accompanies with requestAuthorization method. Without permissions, HealthKit will not allow you to read or write the data. Not all of the types are allowed to be written in HealthKit. Please see https://developer.apple.com/documentation/healthkit The Quantity type is a type which will provide quantity values with an appropriate unit. Call preferredUnits to see which PreferredUnit is used for the Quantity. With invalid unit the quantityQuery, statisticsQuery will fail to retrieve the data.

The method electrocardiogramQuery requires iOS 14.0 and higher. The method heartbeatSeriesQuery requires iOS 13.0 and higher.

Receives events from native side. Channel: health_kit_reporter_event_channel For all stream events, all responses are provided as JSON based payloads.

The list of Platform events:

Call the listed methods above to maintain the stream events from the native side. The workflow:

  1. Function is called in you Flutter app on the Flutter side with Dart.
  2. The registration callback onListen is triggered on iOS Side. See HealthKitReporterStreamHandler.swift
  3. When the appropriate event is detected, the FlutterEventSink will sink the event.
  4. The new event will be handled in listen callback of the received broadcast stream
  5. After handling, the mapped event will be transferred as a ready result in the function's callback onUpdate

This workflow allows you not to call methods on native side in AppDelegate.swift

Please do not keep active multiple event streams, only one at once.

Constructors

HealthKitReporter()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

addCategory(List<Category> categories, Workout workout, {Device? device}) Future<bool>
Adds Category samples to your workout. device is optional.
addQuantity(List<Quantity> quantities, Workout workout, {Device? device}) Future<bool>
Adds Quantity samples to your workout. device is optional.
anchoredObjectQuery(List<String> identifiers, Predicate predicate, {required dynamic onUpdate(List<Sample>, List<DeletedObject>)}) StreamSubscription
Will fetch the actual values as a first data snapshot and notify about data changes. Will call onUpdate callback, if there were changes regarding to the provided identifier inside HealthKit. Provide the predicate to set the date interval.
categoryQuery(CategoryType type, Predicate predicate) Future<List<Category>>
Returns Category samples for the provided type and the time interval predicate predicate.
characteristicsQuery() Future<Characteristic>
Returns Characteristic info.
correlationQuery(String identifier, Predicate predicate, {Map<String, Predicate>? typePredicates}) Future<List<Correlation>>
Returns Correlation samples for the provided identifier, the time interval predicate predicate and optional typePredicates for Category and/or Quantity values.
delete(Sample sample) Future<bool>
Deletes Sample from HealthKit.
deleteObjects(String identifier, Predicate predicate) Future
Deletes all objects related to identifier with predicate.
disableAllBackgroundDelivery() Future<bool>
Disables all previous background notifications.
disableBackgroundDelivery(String identifier) Future<bool>
Disables specific background notifications for type with identifier.
electrocardiogramQuery(Predicate predicate, {bool withVoltageMeasurements = false}) Future<List<Electrocardiogram>>
Returns Electrocardiogram samples for the provided time interval predicate predicate.
enableBackgroundDelivery(String identifier, UpdateFrequency frequency) Future<bool>
Returns a status of calling native method for enabling background notifications about the data changing for the type with the identifier. Set the frequency to get updates on specified time interval.
heartbeatSeriesQuery(Predicate predicate) Future<List<HeartbeatSeries>>
Returns HeartbeatSeries sample for the provided time interval predicate predicate.
isAuthorizedToWrite(String identifier) Future<bool>
Checks if the provided type with identifier is allowed for writing in HealthKit.
observerQuery(List<String> identifiers, Predicate? predicate, {required dynamic onUpdate(String)}) StreamSubscription
Sets subscription for data changes. Will call onUpdate callback, if there were changes regarding to the provided identifier inside HealthKit. Provide the predicate to set the date interval.
preferredUnits(List<QuantityType> types) Future<List<PreferredUnit>>
Returns preferred units for provided types. Usage is only for QuantityType
quantityQuery(QuantityType type, String unit, Predicate predicate) Future<List<Quantity>>
Returns Quantity samples for the provided type, the preferred unit and the time interval predicate predicate.
queryActivitySummary(Predicate predicate) Future<List<ActivitySummary>>
Returns HeartbeatSerie samples for the provided time interval predicate predicate.
queryActivitySummaryUpdates(Predicate predicate, {required dynamic onUpdate(List<ActivitySummary>)}) StreamSubscription
Will fetch the actual values as a first data snapshot and notify about data changes. Will call onUpdate callback, if activity summaries have been changed. inside HealthKit Provide the predicate to set the date interval.
requestAuthorization(List<String> toRead, List<String> toWrite) Future<bool>
Request write/read access to various HealthKit types. Provide toRead and/or toWrite. If you want only read data, please set toWrite as an empty array. Types you can work with are grouped as Enums:
sampleQuery(String identifier, Predicate predicate) Future<List<Sample>>
Returns Sample samples for the provided identifier and the time interval predicate predicate.
save(Sample sample) Future<bool>
Saves Sample in HealthKit.
sourceQuery(String identifier, Predicate predicate) Future<List<Source>>
Returns Source samples for the provided identifier and the time interval predicate predicate.
startWatchApp(WorkoutConfiguration workoutConfiguration) Future<bool>
Returns status of the App on WatchOS device. Expects workoutConfiguration as the main parameter.
statisticsCollectionQuery(List<PreferredUnit> preferredUnits, Predicate predicate, DateTime anchorDate, DateTime enumerateFrom, DateTime enumerateTo, DateComponents intervalComponents, {required dynamic onUpdate(Statistics)}) StreamSubscription
Will fetch the actual values as a first data snapshot and will provide a numerous enumerations as soon as they are ready. Will call onUpdate callback, if there were changes regarding to the provided type inside HealthKit Provide the predicate to set the date interval. Provide the unit for the type. See preferredUnits. Provide the anchorDate as a starting point. Set the time interval with enumerateFrom and enumerateTo accordingly. Set the grouping by intervalComponents
statisticsQuery(QuantityType type, String unit, Predicate predicate) Future<Statistics>
Returns Statistics for the provided type and the, the preferred unit and the time interval predicate predicate.
workoutQuery(Predicate predicate) Future<List<Workout>>
Returns Workout samples for the provided time interval predicate predicate.
workoutRouteQuery(Predicate predicate) Future<List<WorkoutRoute>>
Returns WorkoutRoute sample for the provided time interval predicate predicate.