background_task
0.4.0, released 4 months ago by neverjp.com
Run Dart code in the background using location updates on Android and iOS.
What it does
The plugin keeps a Dart isolate alive by receiving location updates even when the app is in the background or task‑killed. It streams those updates so you can execute custom logic, such as step counting or sending location to a server.
AI-written summary of version 0.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need periodic background processing triggered by location changes
- You want to monitor distance walked, steps, or arrival at a destination
- Your app must continue work after the user puts it in the background
Skip it when
- You need background work unrelated to location
- You require execution after a full app termination on iOS without location callbacks
- Battery‑critical apps that cannot afford constant location polling
Strengths
- Uses native location services (significant‑change on iOS, foreground service on Android)
- Works even when the app is task‑killed (iOS significant‑change, Android foreground service)
- Simple stream‑based API
Weaknesses
- Limited to location‑based triggers; cannot run arbitrary background tasks
- Requires many permissions and native setup, impacting battery
- iOS background execution only while location updates are received
Setup
- Kind
- Plugin (native code)
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 0
Add location permissions (ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION, etc.) and FOREGROUND_SERVICE_LOCATION in AndroidManifest; configure iOS Info.plist with NSLocation* keys and UIBackgroundModes (fetch, location); register DispatchEngine in AppDelegate as shown; optionally use permission_handler to request permissions.
BackgroundTask.instance.stream.listen((event){/* background work */});
await BackgroundTask.instance.start();
await BackgroundTask.instance.stop();Alternatives
Packages that do the same job and could replace background_task.
- geolocator
Provides location updates without the background‑service overhead; suitable if you only need foreground location tracking
97Compare