{"id":32288347,"url":"https://github.com/never-inc/flutter_background_task","last_synced_at":"2026-02-21T02:39:14.065Z","repository":{"id":216636021,"uuid":"741720098","full_name":"never-inc/flutter_background_task","owner":"never-inc","description":"background_task","archived":false,"fork":false,"pushed_at":"2024-09-21T09:42:23.000Z","size":602,"stargazers_count":26,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-23T02:41:14.728Z","etag":null,"topics":["android","dart","flutter","ios","kotlin","swift"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/background_task","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/never-inc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["never-inc"]}},"created_at":"2024-01-11T01:08:38.000Z","updated_at":"2025-08-26T06:14:26.000Z","dependencies_parsed_at":"2024-09-18T07:19:36.618Z","dependency_job_id":"496a0211-27c2-4fd0-a96c-77ac031d8ed1","html_url":"https://github.com/never-inc/flutter_background_task","commit_stats":null,"previous_names":["never-inc/flutter_background_task"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/never-inc/flutter_background_task","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/never-inc%2Fflutter_background_task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/never-inc%2Fflutter_background_task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/never-inc%2Fflutter_background_task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/never-inc%2Fflutter_background_task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/never-inc","download_url":"https://codeload.github.com/never-inc/flutter_background_task/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/never-inc%2Fflutter_background_task/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29671784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T00:11:43.526Z","status":"online","status_checked_at":"2026-02-21T02:00:07.432Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dart","flutter","ios","kotlin","swift"],"created_at":"2025-10-23T02:28:27.449Z","updated_at":"2026-02-21T02:39:14.052Z","avatar_url":"https://github.com/never-inc.png","language":"Kotlin","funding_links":["https://github.com/sponsors/never-inc"],"categories":[],"sub_categories":[],"readme":"# background_task\n\n[![never-light-log](./img/logo_blk.png)](https://neverjp.com)\n\nDeveloped with 💙 by [Never inc](https://neverjp.com/).\n\n---\n\n## Motivation\n\nEnable developers to continue processing even when the application transitions to the background, we have created a package that allows processing to continue using location updates.This package was created with reference to [background_location](https://pub.dev/packages/background_location).\n\nCan be used when you want to run the program periodically in the background.\n\n- Monitor and notify the distance walked and steps.\n- Notification of destination arrival.\n- Tracking location information (sending it to a server).\n\n## Usage\n\n```dart\n// Monitor notifications of background processes.\n// However, Cannot be used while the app is in task kill.\nBackgroundTask.instance.stream.listen((event) {\n  // Implement the process you want to run in the background.\n  // ex) Check health data.\n});\n\n// Start background processing with location updates.\nawait BackgroundTask.instance.start();\n\n// Stop background processing and location updates.\nawait BackgroundTask.instance.stop();\n```\n\nThis is an implementation for receiving updates even when the task is task-killed. In this package, iOS uses [startMonitoringSignificantLocationChanges](https://developer.apple.com/documentation/corelocation/cllocationmanager/1423531-startmonitoringsignificantlocati) and Android uses [ForegroundService](https://developer.android.com/develop/background-work/services/foreground-services).\n\n```dart\n// Define callback handler at the top level.\n@pragma('vm:entry-point')\nvoid backgroundHandler(Location data) {\n  // Implement the process you want to run in the background.\n  // ex) Check health data.\n}\n\nvoid main() {\n  WidgetsFlutterBinding.ensureInitialized();\n  BackgroundTask.instance.setBackgroundHandler(backgroundHandler); // 👈 Set callback handler.\n  runApp(const MyApp());\n}\n```\n\nTo get the latest location information in a task-killed status, set the app to Always.\n\n![ios](./img/ios_location_permission_for_task_kill.png)\n![android](./img/android_location_permission_for_task_kill.png)\n\nThis is an implementation for when you want to stop using the application when it is killed.\n\n```dart\nawait BackgroundTask.instance.start(\n  isEnabledEvenIfKilled: false,\n);\n```\n\nRecommended to use with [permission_handler](https://pub.dev/packages/permission_handler).\n\n```dart\nfinal status = await Permission.location.request();\nfinal statusAlways = await Permission.locationAlways.request();\n\nif (status.isGranted \u0026\u0026 statusAlways.isGranted) {\n  await BackgroundTask.instance.start();\n}\n```\n\n### Setup\n\npubspec.yaml\n\n```yaml\ndependencies:\n  background_task:\n```\n\niOS: Info.plist\n\n```xml\n\u003ckey\u003eNSLocationAlwaysAndWhenInUseUsageDescription\u003c/key\u003e\n\u003cstring\u003eUsed to monitor location in the background and notify to app.\u003c/string\u003e\n\u003ckey\u003eNSLocationAlwaysUsageDescription\u003c/key\u003e\n\u003cstring\u003eUsed to monitor location in the background and notify to app.\u003c/string\u003e\n\u003ckey\u003eNSLocationWhenInUseUsageDescription\u003c/key\u003e\n\u003cstring\u003eUsed to monitor location in the background and notify to app.\u003c/string\u003e\n\u003ckey\u003eUIBackgroundModes\u003c/key\u003e\n\u003carray\u003e\n    \u003cstring\u003efetch\u003c/string\u003e\n    \u003cstring\u003elocation\u003c/string\u003e\n\u003c/array\u003e\n```\n\nTo use an external package (shared_preference etc..) in callback handler, register DispatchEngine in AppDelegate.\n\niOS: AppDelegate.swift\n\n```swift\nimport UIKit\nimport Flutter\nimport background_task // 👈 Add\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n    override func application(\n        _ application: UIApplication,\n        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n    ) -\u003e Bool {\n        GeneratedPluginRegistrant.register(with: self)\n        // 👇 Add\n        BackgroundTaskPlugin.onRegisterDispatchEngine = {\n            GeneratedPluginRegistrant.register(with: BackgroundTaskPlugin.dispatchEngine)\n        }\n        return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n    }\n}\n\n```\n\nAndroid: AndroidManifest.xml\n\n```xml\n\u003cuses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_BACKGROUND_LOCATION\"/\u003e\n\u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE\" /\u003e\n\u003cuses-permission android:name=\"android.permission.FOREGROUND_SERVICE_LOCATION\"/\u003e\n\u003cuses-permission android:name=\"android.permission.POST_NOTIFICATIONS\"/\u003e\n```\n\n## References\n\n- [Executing Dart in the Background with Flutter Plugins and Geofencing](https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124#56b7)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnever-inc%2Fflutter_background_task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnever-inc%2Fflutter_background_task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnever-inc%2Fflutter_background_task/lists"}