How to run code after some delay in Flutter?

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

    (Adding response on old q as this is the top result on google)

    I tried yielding a new state in the callback within a bloc, and it didn't work. Tried with Timer and Future.delayed.

    However, what did work was...

    await Future.delayed(const Duration(milliseconds: 500));
    
    yield newState;
    

    Awaiting an empty future then running the function afterwards.

提交回复
热议问题