You can do it in 2 ways:
-
Using
Timerclass.import 'dart:async'; // Go to Page2 after 5s. Timer(Duration(seconds: 5), () { Navigator.push(context, MaterialPageRoute(builder: (_) => Screen2())); }); -
Using
Future.delayedclass:// Go to Page2 after 5s. Future.delayed(Duration(seconds: 5), () { Navigator.push(context, MaterialPageRoute(builder: (_) => Screen2())); });
The benefit of using Timer over Future is its ability to cancel.