Open
Description
I am using this package to get location update stream.
Everything is good when app is active.
I am using this pacakge with flutter_background_service to send location update event even app is closed.
@pragma('vm:entry-point')
void onStart(ServiceInstance service) async {
await PreferencesManager.init();
const LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10,
);
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
(Position? position) {
print("Location Tracking");
LocationApi locationApi = LocationApi();
locationApi.sendLocation(position?.latitude, position?.longitude);
print(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}');
});
DartPluginRegistrant.ensureInitialized();
if (service is AndroidServiceInstance) {
service.on('setAsForeground').listen((event) {
service.setAsForegroundService();
});
service.on('setAsBackground').listen((event) {
service.setAsBackgroundService();
});
}
service.on('stopService').listen((event) {
service.stopSelf();
});
}
But when I close app, I get this log.
FlutterGeolocator com.example.flutter_background_location_service D Detaching Geolocator from activity
FlutterGeolocator com.example.flutter_background_location_service D Flutter engine disconnected. Connected engine count 2
FlutterGeolocator com.example.flutter_background_location_service D Disposing Geolocator services
FlutterGeolocator com.example.flutter_background_location_service E Geolocator position updates stopped
FlutterGeolocator com.example.flutter_background_location_service E There is still another flutter engine connected, not stopping location service
Any solution for this?