是否有任何类似颤振的课程会像Handler一样工作?

问题描述 投票:4回答:3

任何人都可以告诉,什么相当于颤振的处理程序?我想实现一个持续5秒的启动画面,然后显示另一个屏幕。

java android flutter
3个回答
4
投票

我不认为有类似于Handler类,但你可以使用Future.delayed并在build()渲染不同的UI取决于showSplash

showSplash = true;

new Future.delayed(const Duration(seconds: 5), () {
  setState(() => showSplash = false);  
});

0
投票

Handler.postDelayed() - 用于在特定时间后完成工作

我们可以使用Future.postDelayed(由Günter回答)或者我们也可以使用Timer类。

Timer(Duration(seconds: 5), () {
 // 5 seconds have past, you can do your work
}

Handler.post() - 用于在某个特定时间间隔后继续工作

我们可以使用Timer.periodic函数

Timer.periodic(Duration(seconds: 5), (_) {
  // this code runs after every 5 second. Good to use for Stopwatches
}); 

0
投票
new Future.delayed(new Duration(seconds: 5), () {
  Navigator.pushAndRemoveUntil(
      context,
      MaterialPageRoute(builder: (context) => NewScreen()),
      (Route route) => false);
});

其中NewScreen是您要显示的屏幕,它将显示一个新屏幕。

© www.soinside.com 2019 - 2024. All rights reserved.