https://github.com/icapps/flutter-background-location-tracker
Flutter background location tracker plugin. (Android / iOS)
https://github.com/icapps/flutter-background-location-tracker
Last synced: about 1 year ago
JSON representation
Flutter background location tracker plugin. (Android / iOS)
- Host: GitHub
- URL: https://github.com/icapps/flutter-background-location-tracker
- Owner: icapps
- License: mit
- Created: 2020-12-15T09:50:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-03-10T09:06:33.000Z (about 1 year ago)
- Last Synced: 2025-03-31T07:05:43.666Z (about 1 year ago)
- Language: Kotlin
- Size: 272 KB
- Stars: 33
- Watchers: 7
- Forks: 43
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# background_location_tracker
A new Flutter plugin that allows you to track the background location for Android & iOS
[](https://travis-ci.com/icapps/flutter-background-location-tracker)
[](https://coveralls.io/github/icapps/flutter-background-location-tracker?branch=master)
[](https://pub.dartlang.org/packages/background_location_tracker)
## Android Config
### Update compile sdk
Compile sdk should be at 29 at least.
```
android {
...
compileSdkVersion 29
...
defaultConfig {
...
targetSdkVersion 29
...
}
...
}
```
## iOS Configuration
### Update Info.plist
Add the correct permission descriptions
```
NSLocationAlwaysAndWhenInUseUsageDescription
Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription
Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription
```
Add the background location updates in xcode
Or add the info to the Info.plist
```
UIBackgroundModes
location
```
### Update the AppDelegate
Make sure you call the `setPluginRegistrantCallback` so other plugins can be accessed in the background.
```
import UIKit
import Flutter
import background_location_tracker
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
BackgroundLocationTrackerPlugin.setPluginRegistrantCallback { registry in
GeneratedPluginRegistrant.register(with: registry)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```
## Flutter implementation
Make sure you set the `@pragma('vm:entry-point')` to make sure you can find the callback in release.
```
@pragma('vm:entry-point')
void backgroundCallback() {
BackgroundLocationTrackerManager.handleBackgroundUpdated(
(data) async => Repo().update(data),
);
}
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await BackgroundLocationTrackerManager.initialize(
backgroundCallback,
config: const BackgroundLocationTrackerConfig(
loggingEnabled: true,
androidConfig: AndroidConfig(
notificationIcon: 'explore',
trackingInterval: Duration(seconds: 4),
distanceFilterMeters: null,
),
iOSConfig: IOSConfig(
activityType: ActivityType.FITNESS,
distanceFilterMeters: null,
restartAfterKill: true,
),
),
);
runApp(MyApp());
}
Future startLocationTracking() async {
await BackgroundLocationTrackerManager.startTracking();
}
Future stopLocationTracking() async {
await BackgroundLocationTrackerManager.stopTracking();
}
```
# FAQ:
#### I get a Unhandled Exception: MissingPluginException(No implementation found for method .... on channel ...)
```
This is mostly caused by a misconfiguration of the plugin:
Android Pre v2 embedding: make sure the plugin registrant callback is set
Android v2 embedding: Log a new github issues. This
iOS: make sure the plugin registrant callback is set
```