Time changes every time I change my screen


Above are blocks for screen 1.
whenever I press the button to change the screen from 1 to 2 and again come back to screen 1 the time recorded previously changes to the current time

what I want is for it to hold the time value until value on Firebase doesn't change.

plz help

When you changes screen and go back your variable initializes to empty string . Only when data changes on firebase 2 or 4 time will update again.
If you want to save the value between 2 data changes on firebase or when you change screen you have to use a persistent database like tinyDb.

I have real-time values that come from device1 and 2 via ESP32 in Firebase from there I display those value in my mit-aap but the problem is that when I change my screen 1 to 2 and again come back to screen 1 the clock triggers and changes the time even if there is no change in firebase. I applied the logic that if the value in Firebase changes then only it should trigger the clock.

The value go to empty or changes to a new value ?
In the first case when you come back from screen 2 variable initialize to empty, in the second case there is some changes on firebase that activates the data changes block of firebase .

It gives new value

In firebase that particular tag value does not change but changes happen in device off tag then also it shows new time for device 1 on tag

can you plz suggest any changes so that this won't happen

Something changes in firebase, try to modify the if control using the most specific tag or value for the control .
You can set a notifier in your code to verify when your data changes starts. Could be a trick to know how firebase works and find the error

Show also your structure of Firebase where is the value device on off

1yjass

The tag string is the same for all the items so will start always.
The value device should be a tag and not a value

I can't try now but if you add a notifier inside the if control you can read the value and the tag that run you code

Switching screens loses the values of all global variables.

If you want to keep them, store them in TinyDB and retrieve them on your return.

You can avoid this problem by using stacked Vertical Arrangements instead of Screens.

ok I will try it