i want to start a function after 5 seconds when i press the button just one time , for this i use Timer Class, but when i put it on initState, it start whitout clicking on button,
This is my code :
https://www.dartpad.dev/b6409e10de32b280b8938aa75364fa7b
Timer time;
@override
void initState() {
super.initState();
_time = Timer.periodic(Duration(seconds: 5), (Timer t) {
print('yaaay');
t.cancel();
});
}
void start() {
_time ;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children : [
ElevatedButton(
child:Text('press me'),
onPressed:(){
start();
}
),
]);
);
Thank you !