Handling lists and empty lists in Firebase Realtime Database - has anything changed in MIT App Inventor?

Hi everyone.

I've been having some issues with my app over the past few days and I am working on debugging it. The strange thing is that I haven't changed anything in my blocks, so the question is: anything has changed in MIT App Inventor?

My app interfaces with a Firebase Realtime Database. Users can create and delete their tags (tag1, tag2, etc.). The list of these tags is updated and saved in the same database under the "lista_tags" tag. The structure is

tag1: value
tag2: value
...
lista_tags: tag1,tag2,...

Firebase structure without tags is

Firebase structure with a tag is

In my blocks, I've introduced a global variable "lista_tags" that I manage like this:

1

in web component gotText

and when a new tag (local_ID_annuncio) is generated

4

In the last few days tag "lista_tags" in Firebase can only contain one tag (despite users generating more tags).

During debug I found that the variable "lista_tags" is "not a list"! So, following my blocks, the app completely delete the items in list and add only the last item added.
I think that this is related to the fact that at the beginning, when I have not tags yet, response Content is not a list, so from that moment problems begins.

Questions
1 - Why was my app working until a few days ago?
2 - How can I solve it: how do I manage the response content of the call "lista_tags" tag?
3 - When I don't have any tags, the "lista_tags" tag (empty) disappears from the Firebase structure...why? Is it "normal" ?

You have discovered Firebase Arrays :slight_smile:

To answer your questions:

  1. Not sure what you were doing
  2. The response content from calling back a firebase array is a stringified json array. You need to convert this back to an AI2 list:
  3. Yes, if you set a firebase array to an empty list, the tag will disappear from the firebase console.

    and a call to that tag in Firebase will return null

Hi @TIMAI2
Thank you for your reply regarding Firebase array. It means that I have simply to substitute "jsonTextDecode with Dictionaries" with "jsonTextDecode".

But I have the same behaviour…
I used 3 text labels to show you something

Here the results in my app

Label1

[748988]

Label2

[

748988.0

[

Label3

FALSE

I can only show you what I see:

This generates the same results, after storing a value to the list:

responseContent is a string
global lista_tags is a list

The line feed in Label2's list representation is new with the AI2 matrix data type.

Your AI2 setup is interpreting the returning list as a matrix, not a list.

Update your Companion to the bugfix version in the release notes.

1 Like

Thank you so much! @ABG
You saved me from going crazy.
I've been trying to figure out what happened to my app for days!!

All I had to do was update the companion, and magically everything seems to work!
I'll do more tests to confirm.
Thank you.
You've been very helpful!

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