I am trying to send user's location to Firestore even when the app is killed. I'm successfully able to send data to Firestore when the app is in the foreground or background but unable to send data when the app is killed. Can anyone explain what could be the problem?
I'm using
background_locator: ^1.6.4
Flutter
Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f4abaa0735 (2 weeks ago) • 2021-07-01 12:46:11 -0700
Engine • revision 241c87ad80
Tools • Dart 2.13.4
Dart
Dart SDK version: 2.13.4 (stable) (Wed Jun 23 13:08:41 2021 +0200) on "linux_x64"
This code that I'm trying to execute once data is received
receiverPort.listen(
(dynamic data) async {
if (data != null) {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final LocationDto position = data as LocationDto;
print('data: $position');
final Member member = await FirebaseService().getCurrentUserProfile();
member.currentPosition = '${position.latitude},${position.longitude}';
await FirebaseService()
.updateData(
FirebaseService.memberRef,
FirebaseService.memberChildId,
FirebaseService.getCurrentUserId(),
member.toJson())
.then((value) {});
} else {
print('data is null');
}
},
);
Please let me know if I need to share anything else. Thanks