Wrapped positionStream in new StreamController
MODIFY
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
@@ -158,7 +158,7 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
);
}
- _positionStream = positionStream
+ _positionStream = _wrapStream(positionStream)
.map<Position>((dynamic element) =>
Position.fromMap(element.cast<String, dynamic>()))
.handleError(
@@ -175,6 +175,21 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
return _positionStream!;
}
+ Stream<dynamic> _wrapStream(Stream<dynamic> incoming) {
+ late StreamSubscription subscription;
+ late StreamController<dynamic> controller;
+ controller = StreamController<dynamic>(
+ onListen: () => subscription = incoming.listen((item) => controller.add(item)),
+ onPause: () => subscription.pause(),
+ onResume: () => subscription.resume(),
+ onCancel: () {
+ subscription.cancel();
+ _positionStream = null;
+ },
+ );
+ return controller.stream;
+ }
+
@override
Future<bool> openAppSettings() async => _methodChannel
.invokeMethod<bool>('openAppSettings')

Wrapped positionStream in new StreamController