Reputation:
I am building an app and I want it to show up in the user's notification bar and run in the background even when it's closed. Similar to "KWGT Kustom Widget Maker".
I've tried looking for libraries that allow this, but I can only find those related to java. Are there any available for Dart/Flutter or any other workaround? I am only targeting android devices.
Upvotes: 3
Views: 13889
Reputation: 179
I used a package called flutter_background , which worked for me perfectly.
Upvotes: 2
Reputation: 1059
After searching, I guess you have two solution:
You can use flutter wrapper for both android and IOS platform, but you won't be able to run jobs often than every 15 minutes. If you want to schedule jobs more often, you'll need to write platform dependent code, using the android_alarm_manager
flutter package and background_fetch
for IOS.
You can trigger the correct one using the Platform
function in dart.
Upvotes: 1
Reputation: 6962
You can use the flutter_workmanager plugin.
It's better than the android_alarm_manager
plugin since it uses newer API's on Android and also works with iOS.
Upvotes: 0
Reputation: 1148
The mechanism for this feature involves setting up an isolate. Isolates are Dart’s model for multithreading, though an isolate differs from a conventional thread in that it doesn’t share memory with the main program. You’ll set up your isolate for background execution using callbacks and a callback dispatcher.
For more information and a geofencing example that uses background execution of Dart code, see Executing Dart in the Background with Flutter Plugins and Geofencing, an article in the Flutter Publication on Medium. At the end of this article, you’ll find links to example code, and relevant documentation for Dart, iOS, and Android
Upvotes: 2
Reputation: 137
You should use Isolates for this, also you can use android_alarm_manager or background_fetch libraries
Upvotes: 0