kvs-coder / health_kit_reporter

A Flutter wrapper for the HealthKitReporter library
https://pub.dev/packages/health_kit_reporter
MIT License
38 stars 38 forks source link

Creating a new `anchoredObjectQuery` stream cancels the previous one #20

Closed opsb closed 3 years ago

opsb commented 3 years ago

Describe the bug When you call HealthKitReporter.anchoredObjectQuery and then later call it again to create a new anchoredObjectQuery the original one is cancelled.

To Reproduce Steps to reproduce the behavior:

var originalStream = HealthKitReporter.anchoredObjectQuery(...);
var newStream = HealthKitReporter.anchoredObjectQuery(...); // cancels originalStream

Expected behavior You should be able to create any number of anchoredObjectQuerys that run as independent streams.

Additional context A single AnchoredObjectQueryStreamHandler is registered with the event channel at https://github.com/VictorKachalov/health_kit_reporter/blob/master/ios/Classes/SwiftHealthKitReporterPlugin.swift#L69. AnchoredObjectQueryStreamHandler only has a single query though which is replaced at https://github.com/VictorKachalov/health_kit_reporter/blob/master/ios/Classes/AnchoredObjectQueryStreamHandler.swift#L36 whenever HealthKitReporter.anchoredObjectQuery is called.

I'm new to Flutter/Dart so I'm not sure how this tends to be handled but in other languages using channels I've used an identifier (say a uuid) for the stream that is created for a particular call to HealthKitReporter.anchoredObjectQuery. That way it's possible to have multiple AnchoredQueries on the Swift side and use the uuid to route messages appropriately on the Dart side.

kvs-coder commented 3 years ago

Hi @opsb

I merged your PR, but on a separate branch (1.1.2-prenullsafety), since the package you use there is quite old and not updated to nullsafety, I would not include the code in final 1.3.0 version which will have the concept of nullsafety first.

I fixed some issues releated to overwriting the subs by tracking queries, you may check how it works on master branch