Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter, better performance with Future.delay or Timer?

in flutter, if i need to execute a refresh every 60 seconds or do some code... in performance.. is better to use

Future.delayed(const Duration(milliseconds: (seconds * 1000)), () {

// Here you can write your code
       
});

or it's better

Timer  _timer = new Timer(const Duration(milliseconds: (seconds * 1000)), () {
     // Here you can write your code
});

or (suggested by Omer Gamliel )

   Timer.periodic(Duration(seconds: 60), (timer) {
       // Here you can write your code
   });

what do you think?

like image 386
ecota Avatar asked Sep 13 '25 18:09

ecota


1 Answers

According to the comment of pskink

Documentation

Flutter documentation show that Future.delayed is a Timer masked for convenience by the function Future.delayed to execute only once.

So, they are equal.

like image 173
ecota Avatar answered Sep 16 '25 06:09

ecota