Whenever my home page was reloaded my data was updated but I want to reflect data instantly. That's why I need a method that can refresh my page or method after every 1 second(flutter). pls, help me.
CodePudding user response:
This work's for me :smile:
Timer.periodic(Duration(milliseconds: 2200),
(timer) {
'Your Method'
debugPrint('Timer 1 sec ${timer.tick.toString()}');
});
CodePudding user response:
You can use the Timer.periodic
to run a method every Duration
you specify and using StatefulWidget
n you can run it in initState
like this:
@override
void initState() {
Timer.periodic(Duration(seconds: 1), (timer) {
print("this will execute every second");
});
super.initState();
}
change the print
with your method.
CodePudding user response:
in Your init state call the Timer like this
@override
void initState() {
new Timer.periodic(Duration(seconds: 1), (Timer t) => YourMethod());//api call
super.initState();
}
this will update your full screen