Can someone help me to solve my firebase problem?

Hi guys, can someone help me with my final project for school? I really need to know why my code is not functioning like I need it to. So my app is conected to a db on firebase and my intention is to make a list then send it, but instead of going as a list the last item continues to overwrite above the rest. I don’t know if you can understand, but here are some pictures to explain better. I have little time to finish this so thanks in advance.

1 Like

Each time you start the app, it assumes it is the first time, having the “lista_emergencia” defined as an empty list.

If you want to be able to add to it, you need to preserve that WHOLE list, like retrieving the value from the database before appending to it, as opposed to appending to the empty list.


Thank you very much, I’ll try to do it

Sorry, I can’t get myself to do it… Should this work? When I send it, the value doesn’t get to firebase

No, that won’t work.
You need to provide the key and to add the logic to address the case where “Get” comes back empty handed because that is the first time the program is ever run and that that record does not yet exist.

1 Like

Oh of course… sorry, in my print It seems that I didn’t provide any key, but even why I did It didn’t work ://

Have you included the logic for the first run, when the “Get” finds no record?

I don’t know if I understood it right because I’m not good in english, but here are the results: The list just doesn’t seem to be right

Thank you so much for trying to help me though, you’re the main reason I didn’t freak ou yet. I actually have another screen in this app with almost the same code but It does work quite well as I intended, different from this one.

In your Get block, I am not sure that, if the record is not found, that value is returned as ‘null’ (though it is possible it does); my point is that most look for ‘error’ to not be true,
But, if the value is not null, then it is ALREADY a list. By having a “list” conversion, you are turning the result into a list of a list, which is not what you lista_emergencia should be made directly equal to ‘value’, without the “list” instruction.