2

I want to create a function that runs every x seconds ..

in java there is the

TimerTask

but in flutter what is it?

Gerard_jcr
  • 289
  • 2
  • 13

1 Answers1

7
import 'dart:async'; // import this 

And use Timer class periodic named constructor.

Timer.periodic(Duration(seconds: 1), (timer) {
  // this block runs every second
  // and when you want to stop it, simply call `timer.cancel();` here
});
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440