Firebase numbers random ids by default

Hi, I’m working on something that may be simple.
I have my application that saves information in firebase until there everything is perfect.
but I want it to generate random numbers by default.
I generated manually to identify my tables in realtime database
By hand I wrote example: 2021-05 and all its data in firebase.
what I want is that when scrren1 starts I generate a random number by default.
If I close the app and open it again, it will generate 2 so 3,4,5,6 ect.
I was able to do it, but when I close and reopen it gives me the same number :slightly_frowning_face:

solu2

first of all, this logic will not work always. because maths block should not be empty. It seems you are not generating random number instead generating sequence number. then try this,

Update: (firebase tag should not be a single digit, so better use this

image

whenever you reopen label 1 text will add +1 with previously stored value…

1 Like

You are a genius, you saved me, it works, I could achieve it, I really appreciate your help! :star_struck:

Then avoid this blocks to be used in initialise. Put this procedure on register button click. So in next screen just you call the tinydb alone and avoid other procedure in other screens. So next time while you open the app or coming from screen 2 to screen 1 number will be 1. Upon clicking the button only you will be generating the sequence.

See if you asked the whole earlier then we would suggest you the best way. But as per your topic i was suggested. So you are facing. Actual problem is, you decided to generate orderly the number upon every register. If so you have to use only in button click. In screen initialize you need to call only tinydb

I hope it is clear now

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.