-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Register background locator on use realtime and use background …
…fetch otherwise
- Loading branch information
Showing
4 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:background_locator_2/background_locator.dart'; | ||
import 'package:background_locator_2/location_dto.dart'; | ||
import 'package:background_locator_2/settings/android_settings.dart'; | ||
import 'package:background_locator_2/settings/ios_settings.dart'; | ||
import 'package:background_locator_2/settings/locator_settings.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter_logs/flutter_logs.dart'; | ||
import 'package:locus/constants/app.dart'; | ||
import 'package:locus/constants/values.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
|
||
@pragma('vm:entry-point') | ||
void runBackgroundLocatorTask(final LocationDto location,) {} | ||
|
||
Future<void> configureBackgroundLocator() { | ||
FlutterLogs.logInfo( | ||
LOG_TAG, | ||
"Background Locator", | ||
"Initializing background locator.", | ||
); | ||
|
||
return BackgroundLocator.initialize(); | ||
} | ||
|
||
Future<void> initializeBackgroundLocator(final BuildContext context,) { | ||
final l10n = AppLocalizations.of(context); | ||
|
||
FlutterLogs.logInfo( | ||
LOG_TAG, | ||
"Background Locator", | ||
"Registering background locator.", | ||
); | ||
|
||
return BackgroundLocator.registerLocationUpdate( | ||
runBackgroundLocatorTask, | ||
autoStop: false, | ||
androidSettings: AndroidSettings( | ||
accuracy: LocationAccuracy.HIGH, | ||
distanceFilter: | ||
BACKGROUND_LOCATION_UPDATES_MINIMUM_DISTANCE_FILTER.toDouble(), | ||
client: isGMSFlavor ? LocationClient.google : LocationClient.android, | ||
androidNotificationSettings: AndroidNotificationSettings( | ||
notificationTitle: l10n.backgroundLocator_title, | ||
notificationMsg: l10n.backgroundLocator_text, | ||
), | ||
), | ||
iosSettings: IOSSettings( | ||
distanceFilter: | ||
BACKGROUND_LOCATION_UPDATES_MINIMUM_DISTANCE_FILTER.toDouble(), | ||
accuracy: LocationAccuracy.HIGH, | ||
showsBackgroundLocationIndicator: true, | ||
stopWithTerminate: false, | ||
), | ||
); | ||
} | ||
|
||
Future<void> removeBackgroundLocator() { | ||
FlutterLogs.logInfo( | ||
LOG_TAG, | ||
"Background Locator", | ||
"Removing background locator.", | ||
); | ||
|
||
return BackgroundLocator.unRegisterLocationUpdate(); | ||
} |