Flutter, better performance with Future.delay or Timer?

497

Solution 1

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.

Solution 2

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

Share:
497
ecota
Author by

ecota

Updated on December 25, 2022

Comments

  • ecota
    ecota over 1 year

    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?