0

I need to run a dart code in the background for each 10s even if the application is closed. It's possible? in flutter

I fund a library that runs the code every 15 min but I want to execute the code every 10s

I need to fetch data every 10s if any change the push notification shown to the users

I am using a custom API rest (asp.net core) for data connecting

On click of the notification should open the app.

Thanks in advance.

Mohamed Amine
  • 43
  • 1
  • 6

1 Answers1

-1

Feel free to use something like this:

Timer _backgroundTimer;

@override
initState(){
super.initState();
 _backgroundTimer = Timer.periodic(
  Duration(seconds: 10), (result) {
  /// Do any stuff you want here
}
);
}

@override
dispose(){
 super.dispose();
_backgroundTimer.cancel();
}
emvaized
  • 884
  • 12
  • 23
  • it not working in the background when the is closed – Mohamed Amine Apr 27 '20 at 17:06
  • @MohamedAmine What you're looking for is the ability to launch background services. Currently Flutter doesn't fully supports it, please take a look at this answer: https://stackoverflow.com/a/50109637/11381400 – emvaized Apr 27 '20 at 17:16