任何人都可以告诉,什么相当于颤振的处理程序?我想实现一个持续5秒的启动画面,然后显示另一个屏幕。
我不认为有类似于Handler
类,但你可以使用Future.delayed
并在build()
渲染不同的UI取决于showSplash
:
showSplash = true;
new Future.delayed(const Duration(seconds: 5), () {
setState(() => showSplash = false);
});
我们可以使用Future.postDelayed
(由Günter回答)或者我们也可以使用Timer
类。
Timer(Duration(seconds: 5), () {
// 5 seconds have past, you can do your work
}
我们可以使用Timer.periodic
函数
Timer.periodic(Duration(seconds: 5), (_) {
// this code runs after every 5 second. Good to use for Stopwatches
});
new Future.delayed(new Duration(seconds: 5), () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => NewScreen()),
(Route route) => false);
});
其中NewScreen
是您要显示的屏幕,它将显示一个新屏幕。