Skip to content

Commit

Permalink
making obersver query predicate nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
kvs-coder committed Dec 21, 2021
1 parent 3fd1471 commit fa18d23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class _MyAppState extends State<MyApp> {
}

void observerQuery(List<String> identifiers) async {
final sub = HealthKitReporter.observerQuery(identifiers, _predicate,
final sub = HealthKitReporter.observerQuery(identifiers, null,
onUpdate: (identifier) async {
print('Updates for observerQuerySub - $identifier');
print(identifier);
Expand Down
17 changes: 10 additions & 7 deletions ios/Classes/ObserverQueryStreamHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ public final class ObserverQueryStreamHandler: NSObject {
extension ObserverQueryStreamHandler: StreamHandlerProtocol {
public func setQueries(arguments: [String: Any], events: @escaping FlutterEventSink) throws {
guard
let identifiers = arguments["identifiers"] as? [String],
let startTimestamp = arguments["startTimestamp"] as? Double,
let endTimestamp = arguments["endTimestamp"] as? Double
let identifiers = arguments["identifiers"] as? [String]
else {
return
}
let predicate = NSPredicate.samplesPredicate(
startDate: Date.make(from: startTimestamp),
endDate: Date.make(from: endTimestamp)
)
var predicate: NSPredicate?
if
let startTimestamp = arguments["startTimestamp"] as? Double,
let endTimestamp = arguments["endTimestamp"] as? Double {
predicate = NSPredicate.samplesPredicate(
startDate: Date.make(from: startTimestamp),
endDate: Date.make(from: endTimestamp)
)
}
for identifier in identifiers {
guard let type = identifier.objectType as? SampleType else {
return
Expand Down
6 changes: 4 additions & 2 deletions lib/health_kit_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,14 @@ class HealthKitReporter {
/// Provide the [predicate] to set the date interval.
///
static StreamSubscription<dynamic> observerQuery(
List<String> identifiers, Predicate predicate,
List<String> identifiers, Predicate? predicate,
{required Function(String) onUpdate}) {
final arguments = <String, dynamic>{
'identifiers': identifiers,
};
arguments.addAll(predicate.map);
if (predicate != null) {
arguments.addAll(predicate.map);
}
return _observerQueryChannel
.receiveBroadcastStream(arguments)
.listen((event) {
Expand Down

0 comments on commit fa18d23

Please sign in to comment.