9

I'm trying to figure out a way to keep a Flutter application running even if it's not in focus. For instance have a countdown running and play an alarm sound/show notification on completion, no matter what's running in foreground. Can anyone point me in the right direction? Ideally something that works cross-platform.

I found this thread but it's almost 2 years old, so I'm thinking maybe there has been some development since then.

dan
  • 1,292
  • 2
  • 10
  • 16
  • 1
    This looks like what you might want: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124 – Randal Schwartz Nov 27 '18 at 23:05

1 Answers1

3

This looks like what you might want: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124. It's a nice article on Medium describing how to run things in the background on both iOS and Android, especially using the most recent releases of Flutter.

The official documentation for Flutter in the background is at https://flutter.io/docs/development/packages-and-plugins/background-processes. The key is to run your code in an Isolate, because you won't have access to the GUI Isolate when you are in the background.

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
  • Thanks, I was aware of that article. My problem was actually much more trivial. In my timer app I used the AnimationStatus of Animation to trigger something at the end. This didn't trigger in the background (probably because there's no animation happening when the app is in the background?). If I use a Timer instead to trigger something it works just fine, even if the app is in the background. – dan Dec 04 '18 at 06:27
  • 6
    its not a nice article really... wayyy to complex – Toskan Apr 05 '21 at 19:43