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:
- requestAuthorization
- preferredUnits
- characteristicsQuery
- quantityQuery
- categoryQuery
- workoutQuery
- electrocardiogramQuery
- sampleQuery
- statisticsQuery
- heartbeatSeriesQuery
- queryActivitySummary
- enableBackgroundDelivery
- disableAllBackgroundDelivery
- disableBackgroundDelivery
- sourceQuery
- correlationQuery
- startWatchApp
- isAuthorizedToWrite
- addCategory
- addQuantity
- delete
- deleteObjects
- save
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:
- Function is called in you Flutter app on the Flutter side with Dart.
- The registration callback
onListen
is triggered on iOS Side. SeeHealthKitReporterStreamHandler.swift
- When the appropriate event is detected, the
FlutterEventSink
will sink the event. - The new event will be handled in
listen
callback of the received broadcast stream - 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
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 providedidentifier
insideHealthKit
. Provide thepredicate
to set the date interval. -
categoryQuery(
CategoryType type, Predicate predicate) → Future< List< Category> > -
Returns Category samples for the provided
type
and the time interval predicatepredicate
. -
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 predicatepredicate
and optionaltypePredicates
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
withpredicate
. -
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 thefrequency
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 inHealthKit
. -
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 providedidentifier
insideHealthKit
. Provide thepredicate
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 preferredunit
and the time interval predicatepredicate
. -
queryActivitySummary(
Predicate predicate) → Future< List< ActivitySummary> > -
Returns
HeartbeatSerie
samples for the provided time interval predicatepredicate
. -
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. insideHealthKit
Provide thepredicate
to set the date interval. -
requestAuthorization(
List< String> toRead, List<String> toWrite) → Future<bool> -
Request write/read access to various
HealthKit
types. ProvidetoRead
and/ortoWrite
. If you want only read data, please settoWrite
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 predicatepredicate
. -
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 predicatepredicate
. -
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 providedtype
insideHealthKit
Provide thepredicate
to set the date interval. Provide theunit
for the type. SeepreferredUnits
. Provide theanchorDate
as a starting point. Set the time interval withenumerateFrom
andenumerateTo
accordingly. Set the grouping byintervalComponents
-
statisticsQuery(
QuantityType type, String unit, Predicate predicate) → Future< Statistics> -
Returns
Statistics
for the providedtype
and the, the preferredunit
and the time interval predicatepredicate
. -
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
.