Almoullim / background_location

Flutter background location plugin for Android and iOS
https://pub.dev/packages/background_location
Other
224 stars 236 forks source link

Send http request on getLocationUpdates method #112

Closed DevTiago closed 3 years ago

DevTiago commented 3 years ago

Hey there,

Any chance i can send an http request to a server instead of printing the location on getLocationUpdates method?

BackgroundLocation.getLocationUpdates((location) {
  print(location);
});
DevTiago commented 3 years ago

Well,

I figure that the problem is not the request to server but the background service that not work.

I've managed the AppLifecycleState on my App and when i pause it i set this code:

void didChangeAppLifecycleState(AppLifecycleState state) async  {
    switch (state) {
      case AppLifecycleState.paused:
        await BackgroundLocation.startLocationService();
        await BackgroundLocation.setAndroidConfiguration(5000);
        BackgroundLocation.getLocationUpdates((location) {
          print(DateTime.now());
        });
        break;

And when i pause the app i get the data/time but it stops after 30 seconds (more or less).

DevTiago commented 3 years ago

I solved my problem with this answer.