-1
Today I use so with the code below, but it doesn’t work very well, because when changing screen the query continues to be executed in background.
Future _refresh() async {
if (_statusLote != "finalizado") {
_timer = Timer.periodic(Duration(seconds: 30), (timer) {
print("Com atualizações");
print(_statusLote);
setState(() {
pegarCarcacas();
});
});
} else {
print("Sem atualizações");
print(_statusLote);
closeTimer();
}
}
Since it’s a new user, it’ll be a tip for us to help you better. Edit your question by mounting the full scenario of your problem by clearly explaining your code you propose to solve. Then enter functional codes so that members of the community can understand and help you better. Also mention what you have done of attempts to resolve if you have tried anything. Do not be afraid to detail, as long as the information helps in understanding, details are very welcome.
– Leonardo Paim
If that’s what I understand, your problem is that when you leave the screen where you have this snippet of code the app should stop making queries. Is that right? If it is within this Timer that queries occur, wouldn’t there be some process in your code that you can use to pause it when directed to the next screen? Anyway, with the details it’ll be easier to help you.
– Leonardo Paim
So for my needs I need a new query and the return of it along with the screen update to be updated every 30s, until ok. Problem and when the user leaves this screen, the query continues to be performed. The return of the query brings a status information that is changed in my backend, however this change can take up to hours, it would not be appropriate to wait only this event occur for the consultations sessarem. I really want to solve this unexpected error of the query that is running even if it is not on the screen where it was launched.
– Weberth Moreira
Solved: I removed my _refresh() function from Build and added it to initstate(). Also I involved the build in a Willpopscope, with this I can lock the back button and run the cancellation of Periodic time. Thank you all for your attention.
– Weberth Moreira
I’m glad you solved your problem. Now that you have your solution, I recommend that you post it in response format so it can be better used in the future. Another point I recommend is about the "chopped" codes, because from what I noticed, your question did not make clear how the structure of your class was and this directly affects the suggestions for correction. If you decide to post the solution put your full class in the answer.
– Leonardo Paim
@Weberthmoreira answer your question with the way you solved there, this can help anyone who has the same problem in the future...
– Matheus Ribeiro