How to run code after some delay in Flutter?

前端 未结 10 1510
無奈伤痛
無奈伤痛 2020-12-23 00:24

I\'d like to execute a function after a certain delay after my Widget is built. What\'s the idiomatic way of doing this in Flutter?

What I\'m trying to achieve: I\'

10条回答
  •  时光说笑
    2020-12-23 00:51

    import 'dart:async';   
    Timer timer;
    
    void autoPress(){
      timer = new Timer(const Duration(seconds:2),(){
        print("This line will print after two seconds");
     });
    }
    
    autoPress();
    

提交回复
热议问题