ecota
ecota

Reputation: 101

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?

Upvotes: 4

Views: 1390

Answers (2)

ecota
ecota

Reputation: 101

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.

Upvotes: 3

Manu López
Manu López

Reputation: 11

A delayed runs only once so I think Timer is the better one

Upvotes: 1

Related Questions