Baseflow / Baseflow/flutter-geolocator

Geolocator position updates stopped

Open
#1,252 25 comments 15 reactions 0 assignees View on GitHub
background-foreground-location P2 platform: android type: bug
Dominant language
Dart
Stars
1.3k
Forks
803
Avg merge
8h 16m
Merged PRs (30d)
1

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.
```dart
@pragma('vm:entry-point')
void onStart(ServiceInstance service) async {
await PreferencesManager.init();
const LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 10,
);
StreamSubscription 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?

Contributor guide

Open the contributing guide

Research direction

Start at the onStart entry point and the Geolocator.getPositionStream call, then reproduce the behavior by closing the app while monitoring the Android logs shown in the report. Trace the engine detach and location-service disposal messages; done means position updates continue after the app is closed without the reported stop.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart, flutter
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.