anchoredObjectQuery static method
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.
Implementation
static StreamSubscription<dynamic> anchoredObjectQuery(
List<String> identifiers, Predicate predicate,
{required Function(List<Sample>, List<DeletedObject>) onUpdate}) {
final arguments = <String, dynamic>{
'identifiers': identifiers,
};
arguments.addAll(predicate.map);
return _anchoredObjectQueryChannel
.receiveBroadcastStream(arguments)
.listen((event) {
final map = LinkedHashMap<String, dynamic>.from(event);
final samplesList = List.from(map['samples']);
final samples = <Sample>[];
for (final String element in samplesList) {
final json = jsonDecode(element);
final sample = Sample.factory(json);
if (sample != null) {
samples.add(sample);
}
}
final deletedObjectsList = List.from(map['deletedObjects']);
final deletedObjects = <DeletedObject>[];
for (final String element in deletedObjectsList) {
final json = jsonDecode(element);
final deletedObject = DeletedObject.fromJson(json);
deletedObjects.add(deletedObject);
}
onUpdate(samples, deletedObjects);
});
}