Reputation:
Can anyone tell, what is equivalent to handler in flutter?. i want to implement a splash screen which will last for 5 seconds and after another screen will be shown.
Upvotes: 5
Views: 4298
Reputation: 1105
new Future.delayed(new Duration(seconds: 5), () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => NewScreen()),
(Route route) => false);
});
where NewScreen
is the screen you wish to show, it will show a new screen.
Upvotes: 0
Reputation: 267534
We can either use Future.postDelayed
(as answered by Günter) or we can use Timer
class too.
Timer(Duration(seconds: 5), () {
// 5 seconds have past, you can do your work
}
We can use Timer.periodic
function for this like
Timer.periodic(Duration(seconds: 5), (_) {
// this code runs after every 5 second. Good to use for Stopwatches
});
Upvotes: 3
Reputation: 657268
I don't think there is something similar to a Handler
class, but you can just use Future.delayed
and in build()
render a different UI depending on showSplash
:
showSplash = true;
new Future.delayed(const Duration(seconds: 5), () {
setState(() => showSplash = false);
});
Upvotes: 7