Having trouble making a synced list in firebase

Hey guys, so basically, I am trying to make an app where a synced list of strings is shown through Firebase. The thing that is stuffing my whole app up is label’s being set to null by Firebase or Thunkable (idk who). Now, I don’t think null is set as a string as I cant change it to something like “” to make it empty. I included a link to my code and a screenshot to my app, thanks. If you have any ideas of how I can do this more efficiently or set the null value to nothing, that would be great. Thanks :slight_smile:
https://imgur.com/a/zQne5b0

1 Like

Do Event2 Event3 and so on exist? I mean, has anything been saved with the tag Event2 and Event3 already?

If they don’t, then the RealtimeDB Get function ought to return a value that is “null” (null is x00, sometime displayed as ^@), but will also set ‘error’ to true, it is up to you to use the error set to true to provide either a replacement stand-in value or to prevent the non pertinent event from being displayed. In fact, that would also be the ideal spot to set the visibility of the various event.

1 Like

Can you show us how you have data saved in firebase? That might help us better understand your nesting.

1 Like

us ??

How many of you are there? Are you part of the Borg collective??:wink:

You save data symmetrically to how you recover them, except that you decide how to call the key (in the example, the key is a combination of the word “Event” and the content of a variable “myvalue” which presumably you’d set to 1, 2, 3 and so on as a function of how many event you’ve already saved.
And the stuff saved in value can be anything: a number, a text, a list, and object with several properties, etc.
Warning: saving data using a key that already exists REPLACES the data that was there before; that old data is completely erased.

image

2 Likes

Resistance is futile

1 Like

Can you show us what your Firebase looks like? you can scribble out the values.

Also try setting the label to the error that it gives back. Maybe your Firebase rules are set to false?

Set the label to the error block and see what it says.

Event1: “Meeting 11/07/19”
Event2: “Meeting 12/07/19”
etc.

Event1: “Meeting 11/07/19”
Event2: “Meeting 12/07/19”
etc.

Go into Realtime Database in Firebase. Under the rules tab, is Read And/Or Write enabled to True? It should look like this:

My problem has nothing to do with read/write (it is already public), but thanks :slight_smile:

Ah so you do receive a value? I thought you did not, my apologies.

Does the label only show null when the Firebase value is set to nothing? As in it is empty?

If this is the case, you could make a simple if statement, if value = null set text to nothing (text block with nothing in it)

Or if the value it receives isn’t null and Thunkable is doing this, you could set the label, then check if it = null, then set the text to nothing then set it to visible (it starts invisible).

Or is that not your issue either :stuck_out_tongue:

Aadi,

Do you actually have values associated with those keys? Have you checked your Realtime Database in Firebase? If the answer is yes to both of those then the problem is somewhat mysterious. The behavior that you are seeing is consistent with what you would expect if there were, in fact, no values yet set for those keys.

One thing that may be confusing you is the fact that the Realtime DB blocks are all asynchronous, which meant that they are executed separately from the rest of the code (and each other). Consequently, all the blocks after the 'Realtime_DB call Get key "Event5" ...' block are not, in fact, guaranteed to execute after that block is complete. In fact, it is quite likely that all those blocks, which check the text of various labels etc., will be run before all the 'Realtime_DB call Get key ...' blocks get their values and set those labels! If you really want to make sure that all those labels are set before you run the rest of the blocks you have to nest each 'Realtime_DB call Get key ...' block inside the previous one (i.e. inside the 'then do' slot) and then put all those blocks that currently appear after the 'Realtime_DB call Get key "Event5" ...' block inside that block’s 'then do' slot, after the 'from lblEvent5 set Text ...' block.

You can avoid all that trouble and make life much easier for you, though, if you use Cloud Variables rather than the Realtime Database component. Behind the scenes they use the Firebase Realtime Database to store their values (and use your provided Firebase API key and URL) but they are much simpler to use and they take care of of handling all the asynchronous crud, so that, for example, if you set a cloud variable and then get that cloud variable, our code will ensure that the setter block is complete before the getter block (or any subsequent block) is executed. No weird 'then do' slots (nested or otherwise) are required! The name of the Cloud variable ends up being the Firebase key. See the documentation for Cloud Variables here.

-Mark

Hi Mark, one question please: When you use cloud variables (for saving, reading, updating, etc.) how to know if there is an issue, i mean an “error”. When you use Realtime DB blocks you can know easily if there is an error, how about when using just cloud variables?. thanks in advance!

@Mark Cloud variables are sweet, but they have a limited application value, IMO unless someone can explain differnetly.

Can these be used for secure data storage for individual users. see this example

Screen Shot 2020-03-02 at 1.41.55 PM

i just finished the backbones of a cloud note storage app. the premise being, that you can login on any device and see your list. that means husband and wife can both have the app, use the same login, and wifey can add crap to husbands to do list or vice versa.

can a cloud variable be used to do something like this?