Reputation: 133
I need to run a dart code for each 30s even if the application is closed. Is it possible?
Some workarounds suguested is use AlarmManager for Android, but, I not found solution for iOS.
Upvotes: 10
Views: 9953
Reputation: 774
try using these two packages
https://pub.dev/packages/workmanager
https://pub.dev/packages/flutter_background_service
Upvotes: 0
Reputation: 17
Yes its possible you can run a flutter app in background even if the app is closed using the following package:
https://pub.dev/packages/flutter_background_service
Upvotes: -1
Reputation: 993
There's no good article on how to implement an isolate to work when the app is closed without running some native code. In total, I have spent 2 full days trying to find a package for this, but nothing exists that works. Flutter_Isolate doesn't run when app is killed and Flutter Workmanager can only do print statements but can't take in any functions or any method call. Ultimately pathetic and very annoying. The only solution seems is to write native code to handle background tasks when app is closed. Shame on flutter.
Upvotes: 7
Reputation: 3315
Yes, it is possible. You can run Flutter in background.
In Flutter, you can execute Dart code in the background.
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.
Source: Background processes
Upvotes: 3