Closed mohamadkenway closed 3 months ago
There is an example in my project list that uses the fl_location plugin to start a background location service.
https://github.com/Dev-hwang/flutter_foreground_task_example/tree/main/location_service
I will check out other plugins.
@mohamadkenway
Please let me know what detail error occurred.
It worked fine when I used gelocator ^13.0.1
** tested env **
Flutter 3.22.2 / Dart 3.4.3
Flutter 3.10.0 / Dart 3.0.0
Real Device
- Galaxy Note 10 (Android 12)
- Galaxy Fold 4 (Android 14)
Virtual Device (with Google Play)
- Android 14
- Android 13
- Android 12
class GeolocatorServiceHandler extends TaskHandler {
StreamSubscription<Position>? _streamSubscription;
@override
void onStart(DateTime timestamp) {
_streamSubscription = Geolocator.getPositionStream().listen((position) {
final double lat = position.latitude;
final double lon = position.longitude;
// Update notification content.
final String text = 'lat: $lat, lon: $lon';
FlutterForegroundTask.updateService(notificationText: text);
print('notificationText: $text');
});
}
@override
void onRepeatEvent(DateTime timestamp) {
// not use
}
@override
void onDestroy(DateTime timestamp) {
_streamSubscription?.cancel();
_streamSubscription = null;
}
}
Hello again I detected my problem I was used trust_fall package in my project without any calling function and it has much load on application and geolocator package after removing that, everything gone to heaven
Hello I have a problem when trying to implement geolocator or location package inside of foreground service It mostly is in android 13 and 14 but sometimes has problem in other androids Anyone has implemented this feature ?