How can i pull all data in firebase to list in thunkable?

Tonight I wondered why MIT App Inventor (which I tried before Thunkable) uses two different blocks to read data from a database: “GetValue” (call) and “GotValue” (receive). Maybe to give the app the time to receive the requested data? Thunkable only uses one block (Get)… so I tried to insert a pause before evaluating the answer.

And it WORKS!

Hey @bellacopia, I think the issue you were experiencing is because instructions that are nested within the purple block occur asynchronously.

More clearly put the instructions within the purple block run on their own,

so. if you were running in a straight line, and you got to a purple block with a “then do” section, your app now take two paths.

  1. the straight down path. The app will not only do the purple method block but then it will also execute the code immediately below the purple block once it has begun its task.

2. the ‘then do’ path This refers to the “then do” section of the purple method block.
Screen Shot 2020-03-22 at 9.33.37 AM

These blocks occur asynchronously. This means that they work on their own time. Another way to think about it is, The app is now executing any code in this section plus what’s below the purple block at the same time.

That said if blocks below the method block require the code from within the method block, and your app moves too quick or the data/computations/code execution takes too long in the asynchronous “then do” section,. In other words, the app code tries to use the results of the ‘then do’ before that data is ready.

Does this make sense?

you could also make something like this. you’d put the blocks in the green box, minus the delay, below the if/'then block in the ‘then do’ section of the realtimeDB Get Call

2 Likes

Hi Jared,

unfortunately what you suggest me to do was my first choice, which is the first way I tried to create the selection of stores that have a given property. But it does not work. I tried and tried again for three days without getting the result, but what’s worse is that the errors were sometimes different and random, not reproducible. And this is very worrying. Thanks anyway for your help

1 Like

are you sure that this produces a list of all your tags?

would this do the same?
Screen Shot 2020-03-23 at 1.13.29 PM

now that I think of it, @actech has an example of this in his demo app! find that and you will find your answer

1 Like

Your CreaTagLIST function that you copied from me was a big fat HACK when Thunkable was being buggy.

Try out my new preferred approach for getting lists out of firebase:

4 Likes

I know this is a bit late, but I came up with a solution to both propblems: how to access a firebase database and how to extract from a JSON hierarchy.

Notice that loading is a two step process 1) Use the SAVE block to initilize the object on firebase (weird, but necessary). Then you can reference the object using the set block to populate the variable. Now the firebase data is accessible using thunkable VARIABLE blocks. No need to use the Get and save blocks.

You can access the data using the variable blocks, but that doesn’t address how to drill down deep into the hierarchy. The GetProperty function resolves that issue. The KeyPath parameter works just like in MIT App Inventory. Object are specified using the name, and list are accessed using the position (0 is the first position). The GetProperty function works on firebase and local JSON objects.


2 Likes

Hi All,

Thank You for the insights. I tried following them but am not able to get data from Firebase although am able to successfully sent it to firebase. Kindly see the code at

https://x.thunkable.com/copy/1937e97eee08625cc68b53f8dd56c2de.

What ever data I save in Firebase, I want to retrieve ALL that data at different times, by clicking on BACK button.

I will be really grateful if any one of you can help.

thank in advance.

1 Like

To find a problem, display the values of blocks and errors on the screen to identify the block that contains incorrect data.

1 Like

I took a look at your project.

I was having a little trouble following what you were trying to do with your blocks. I added a few block for the LONG CLICK events that save data to a cloud variable then retrieve it into the list control. I Think that is what you were trying to do.

You might also try getting the screen to work using either APP or STORED variables, then move them to the cloud. That way you can determine if the problem is with the cloud/firebase connection or your other blocks.

I hope that helps.

1 Like

Hi,

Thanks a lot for your reply. I did try exactly the way you said, but its not working for me. After long click of the Done as well as Back buttons, nothing happens.

I am able to read data into Firebase from Text_MS1 & Text_MS2 and also able to display data into app from Firebase however I only get the last entry displayed and am not able to display the entire list. PFA the Firebase sample data for reference.

1 Like

Could you please show your blocks and an image of the screen with the results?

Based on the realtime data in your last post, it looks like you might be creating two separate milestone objects instead of one milestone object with 2 properties.

1 Like

Hi,

Thanks again for reply. Have attached 3 screen shots.

Design - The design of the app
Block 1 - Blocks where I have initiated variables, defined how to enter text and then how to write it to Realtime DB. I am entering Milestone No. in Text_MS1 and Milestone details in Text_MS2
Block 3 - Blocks where I am trying to retrieve all the Milestone nos. and Milestone details after clicking Back button

1 Like

Hi guys,

I was able to get the problem solved and I was able to read all the data from Firebase to the app. But now there is a 2nd poblem :slight_smile: - when ever I reopen the app, the old data doesnt get captured.

Do have a look at my project and suggest if you have any solution. My project link is
https://x.thunkable.com/copy/55d15a229db93d07676ed7cdb64d73e2

1 Like

I have kind of the same issue. I have this database structure:
image

I want to collect data from it and present it in a list viewer. But whatever I tried, some other loops to, I did not get anything in my list. This is the block I used for that:
image

Do you have any idea how to fix this?

1 Like

h.s.vreemancru4v4,

I have seen and experienced the same problem. Many people have this issue. The problem is that the Realtime_DB1 Get block is asynchronous. If you want to use it more than once, you must tell Thunkable to wait until it is finished.

There are many possible solutions. Below is my current favorite solution.

Create a Get Cloud Property function EXACTLY as show. You can then use this function anywhere you would otherwise use the Realtime_DB1 Get block as I show in the example “Any Button” click event. This example uses a list parameter called “KeyPath” to map the JSON key hierarchy. The Return values is whatever it finds at the end of the path. For your example, it returns the value in Title.

Happy Thunking!

2 Likes

Hi I am a newbie. I have the same problem. So the list of data that i am trying to get from my firebase is as follows


I tried to follow the solution closely. However i cant seem to find the COMPONENT block.

I am not able to get my list of data from firebase. May I know where i went wrong? Thank you.

2 Likes

The easiest way to start is to open a screen and add a List Viewer in it. Then in the block screen add this code

If you have already connected your firebase to your project, you should see a list of all vehicles in the screen.

2 Likes

Can you please explain more
I need this too
I have a product that I have it in the fierbaas
And I want to show them in my app by the data viewer

2 Likes

Please note that DVL (Data Viewer List) requires a direct connection to a table and cannot be used with Firebase directly.

For the example of the vehicles, if you want the data displayed in a DVL instead of the List Viewer then you will need a Local Data Source. You will use a list variable to store the values from Firebase and then you will loop through all the values in the list and save the values in the Local Data Source table you created. This table is connected with the DVL and the data will show in the screen this way.

I hope this is clear.

2 Likes

but like that the app will not work slowly ؟؟

by the way
Do you have Example app such as usual :sweat_smile:

thank you

1 Like