How to run code after some delay in Flutter?

前端 未结 10 1525
無奈伤痛
無奈伤痛 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:50

    Trigger actions after countdown

    Timer(Duration(seconds: 3), () {
      print("Yeah, this line is printed after 3 seconds");
    });
    

    Repeat actions

    Timer.periodic(Duration(seconds: 5), (timer) {
      print(DateTime.now());
    });
    

    Trigger timer immediately

    Timer(Duration(seconds: 0), () {
      print("Yeah, this line is printed immediately");
    });
    

提交回复
热议问题