How to run code after some delay in Flutter?

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

    Just adding more description over the above answers

    The Timer functionality works with below duration time also:

    const Duration(
          {int days = 0,
          int hours = 0,
          int minutes = 0,
          int seconds = 0,
          int milliseconds = 0,
          int microseconds = 0})
    

    Example:

      Timer(Duration(seconds: 3), () {
        print("print after every 3 seconds");
      });
    

提交回复
热议问题