Call a Function Repeatedly in Flutter?
If you’re a flutter developer, you may have come across a situation where you need to call a function repeatedly. Maybe you need to call it every second, or maybe every hour. Whatever the case may be, there’s an easy way to do it in a flutter. In this blog post, we’ll show you how to call a function repeatedly in flutter so that you can get on with your app development.
In Dart and Flutter, we use the Timer class to call a function at a defined interval. The Timer class is a handy way to fire an event once or repeatedly. You can configure your timer for different durations, and it will count down from that point until 0 minutes have passed – at which point either fire one specific callback function, goes off with no warning if set as-is in milliseconds options available include celebrating birthdays!
final Duration period = Duration(seconds: 5); Timer.periodic(period, (Timer timer) { print('The 5 minutes come.'); //cancel the timer if a condition met if(condition){ timer.cancel(); } });