10

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.

Ulysses Alves
  • 2,297
  • 3
  • 24
  • 34
Mauro Alexandre
  • 133
  • 2
  • 7
  • See https://stackoverflow.com/a/59057145/6668797, also https://pub.dev/packages/workmanager – TWL Nov 26 '19 at 18:44

4 Answers4

6

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.

Axes Grinds
  • 756
  • 12
  • 24
  • I haven't solved it actually. I've been developing the code on other aspects. But there seems to be no other alternative than using native code. – Axes Grinds Dec 27 '20 at 04:38
  • I found out that there is really no solution on IOS. to run a task after app is terminated. but for android you can use foreground service to run a long running task. you should sort of accept that IOS is different and is out of your hand – alireza easazade Dec 27 '20 at 18:36
  • Well I found out that there are solutions on iOS that involves native code. I just don't have an iOS machine to test it yet. – Axes Grinds Dec 28 '20 at 00:04
  • @AxesGrinds can you share iOS native code for killed app? – Chirag Kothiya Mar 03 '22 at 13:30
3

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

Rubens Melo
  • 3,111
  • 15
  • 23
0

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

0

try using these two packages

https://pub.dev/packages/workmanager

https://pub.dev/packages/flutter_background_service

DiyorbekDev
  • 706
  • 1
  • 5
  • 19