Lookup values in two different collections.

Actions & Logic

I'm just blanking on this on my first full fledged app.

User logins and is taken to a User Dashboard page. On that page, I have a Backend Query to query my "users" collection in Firestore so that I can display attributes related to the Authenticated User.

One of the fields in the "users" collection is how many "Requests" that subscriber is allocated during the current month. That displays fine.

Lower on the page I have a Listview that populates a list of all the "Requests" that that user has created. That is coming from my "requests" collection in the same Firestore.

Where I'm running into an issue is that I want to count the current number of "Requests" for that user, subtract it from the allocated monthly amount and then display their remaining amount available.

I'm having a hard time with this because of only having one Backend Query available.

What have you tried so far?

I tried to create a Page Variable called requestedItems (type integer), created an Action on page load that queried the "requests" collection for a count and then outputted a variable called scheduledRequests. Then I tried creating a Code Expression that subtracted the two.

At first I left the Initial Value for scheduledRequests blank and when I referenced that in the Code Expression I made it nullable. I was thinking that was necessary in case there were no scheduledRequests. The Code Expression checking gave me errors stating:

A value of type 'int?' can't be assigned to a variable of type 'num' because 'int?' is nullable and 'num' isn't.
A value of type 'num' can't be returned from a function with return type 'int?'.


So now I set the initial value of scheduledRequests to be 0 and made scheduledRequests not nullable in the Code Expression This works but I momentarily get an unexpected null error when running a Test. It goes away in a flash and then the count works as expected but it still flashes.

Is this because the "On Page Load" action is loading after the page loads and the Code Expression is receiving a null value? Is my error on the Code Expression because one is being treated as a number and one is an integer? Not sure I understand how to change that.

Any other ideas?

Thanks!

Did you check FlutterFlow's Documentation for this topic?
Yes
1