In the question "Open a view after a delay", copsOnRoad gives the following result:
import 'dart:async';
// 1. Option with Timer
Timer(Duration(seconds: 5), () {
// 5s over, navigate to a new page
Navigator.pushNamed(context, MaterialPageRoute(builder: (_) => Screen2()));
});
// 2. Option -- Using Future.delayed class
Future.delayed(Duration(seconds: 5), () {
// 5s over, navigate to a new page
Navigator.pushNamed(context, MaterialPageRoute(builder: (_) => Screen2()));
});
I would like to give the user an option to stop the execution of Navigator.pushNamed during the 5 seconds while waiting. How is that possible?