user7159358
user7159358

Reputation:

How to keep my flutter app running in the background when close?

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

Answers (5)

Aghiad Alzein
Aghiad Alzein

Reputation: 179

I used a package called flutter_background , which worked for me perfectly.

Upvotes: 2

snaipeberry
snaipeberry

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

timr
timr

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

Mohammed Mahmoud
Mohammed Mahmoud

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

ulmas
ulmas

Reputation: 137

You should use Isolates for this, also you can use android_alarm_manager or background_fetch libraries

Upvotes: 0

Related Questions