You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
戴余标
ee40fe3df7
|
2 years ago | |
---|---|---|
.dart_tool | 2 years ago | |
.idea | 2 years ago | |
example | 2 years ago | |
lib | 2 years ago | |
test | 2 years ago | |
.packages | 2 years ago | |
CHANGELOG.md | 2 years ago | |
LICENSE | 2 years ago | |
README.md | 2 years ago | |
flutter_background_service.iml | 2 years ago | |
melos_flutter_background_service.iml | 2 years ago | |
pubspec.lock | 2 years ago | |
pubspec.yaml | 2 years ago |
README.md
flutter_background_service
A flutter plugin for execute dart code in background.
Android
- No additional setting is required.
- To change notification icon, just add drawable icon with name
ic_bg_service_small
.
iOS
-
Enable
background_fetch
capability in xcode (optional), if you wish ios to executeIosConfiguration.onBackground
callback. -
For iOS 13 (using
BGTaskScheduler
), insert lines below into your ios/Runner/Info.plist
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>dev.flutter.background.refresh</string>
</array>
Usage
- Call
FlutterBackgroundService.configure
to configure handler that will be executed by the Service. - Call
FlutterBackgroundService.start
to start the Service ifautoStart
is not enabled. - Since the Service using Isolates, You won't be able to share reference between UI and Service. You can communicate between UI and Service using
invoke()
andon(String method)
.
Migration
sendData()
renamed toinvoke(String method)
onDataReceived()
renamed toon(String method)
- Now you have to use
ServiceInstance
object insideonStart
method instead of creating a newFlutterBackgroundService
object. See the example project. - Only use
FlutterBackgroundService
class in UI Isolate andServiceInstance
in background isolate.
FAQ
Why the service not started automatically?
Some android device manufacturers have a custom android os for example MIUI from Xiaomi. You have to deal with that policy.
Service killed by system and not respawn?
Try to disable battery optimization for your app.