statisticsCollectionQuery static method
StreamSubscription
statisticsCollectionQuery(
- List<
PreferredUnit> preferredUnits, - Predicate predicate,
- DateTime anchorDate,
- DateTime enumerateFrom,
- DateTime enumerateTo,
- DateComponents intervalComponents, {
- required dynamic onUpdate(),
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
Implementation
static StreamSubscription<dynamic> statisticsCollectionQuery(
List<PreferredUnit> preferredUnits,
Predicate predicate,
DateTime anchorDate,
DateTime enumerateFrom,
DateTime enumerateTo,
DateComponents intervalComponents,
{required Function(Statistics) onUpdate}) {
final arguments = {
'preferredUnits': preferredUnits.map((e) => e.map).toList(),
'anchorTimestamp': anchorDate.millisecondsSinceEpoch,
'enumerateFrom': enumerateFrom.millisecondsSinceEpoch,
'enumerateTo': enumerateTo.millisecondsSinceEpoch,
'intervalComponents': intervalComponents.map,
};
arguments.addAll(predicate.map);
return _statisticsCollectionQueryChannel
.receiveBroadcastStream(arguments)
.listen((event) {
final json = jsonDecode(event);
final statistics = Statistics.fromJson(json);
onUpdate(statistics);
});
}