Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer is not worked in background flutter

This code is not printed, when app go to background in iOS.

Timer.periodic(Duration(seconds: 1), (timer) { print('timer'); }

I need to save state to database and play sound after finishing timer. But timer counter minimum is 1 minute. So it means at minimum after 1 minute timer will be finished. This value will be set by user. During this interval device maybe locked. Even if device is locked, app must save state after finishing timer.

like image 509
Shohin Avatar asked Jul 26 '26 05:07

Shohin


1 Answers

Running dart code in background is not a trivial task. You can read this: https://docs.flutter.dev/development/packages-and-plugins/background-processes

Or can check this plugin: https://pub.dev/packages/flutter_background_service

like image 165
yelliver Avatar answered Jul 28 '26 21:07

yelliver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!