I'm a newbie and I'm stuck with the following problem:
I'm creating an app that checks two variables (x and y) every n second. The problem is, after some seconds the screen goes off and the Timer.periodic seems to wait for the user to turn on the screen again.
Everything is working as expected on debug mode because the screen doesn't turn off. But when I flutter clean / flutter build/flutter install the app don't work as expected if the screen goes off.
For example, if n = 15 var counter will reach 4, in debug mode, in ~1min. In release mode counter will reach 4 in more than 10 minutes.
void timerfunction() {
timer = Timer.periodic(Duration(seconds: 15), (Timer t) {
var firstx = x;
var firsty = y;
Future.delayed(Duration(seconds: 5), () {
var secondx = secondy;
if (firstx == secondx && firsty == secondy && counter != 4) {
counter = counter + 1;
print(counter);
print('Same');
);
} else if (counter == 4) {
dothings();
timer?.cancel();
shownotification();
} else {
counter = 0;
print('Different');
}
print('delayed execution');
});
});
}
I expect the timer to execute dosomething() after ~1 minute if x and y are equals.