Create document with data from 2 other firestore collections

Database & APIs

Hello guys, I'm stuck on this for 4 days already so any push in the right direction would be much appreciated. I'm making an app for an apartment cleaning business.

I have 3 collections: user collection, apartment collection and assigment collection (which contains both a doc ref to user and apartment collection).

Now I want a button ("Assign") on my admin page to create a document in the assignment collection (basically by assigning an apartment to a specific user to clean).

I tried to tackle this issue with page state variables selectedUser and selectedApartment (I don't know if this is the correct or best way to handle this tho) - which are doc references to their respective collection.

As u can see I have the dropdown menu (with a backend query to the user collection) set the value of selectedUser a reference (although this does not work, it always chooses the first item in the list - I cannot choose the widget state as the value)

On the bottom of the page I have a listview showing the results of the search bar. The Assign button should first set the value of the page state isSelectedApartment to the selected apartment (this works as intended) and then create a document in the third collection (assignments). This should make a new document with the selected apartment and the user that was chosen in the dropdown. As I stated before, the document creation works but the userId is always the first user in the dropdown list, no matter which one you select.

The listview in the middle of the screen should show the apartments that are assigned to that user (one user will be assigned multiple apartments to clean but each apartment assigned will be a separate document in the assignment collection), with the cross icon hopefully being able to delete the document (for when the admin made an error). I'm not sure how to implement this just yet.

Can anyone help me out here? I'm stuck on this for so long and I really want to move on.

Thanks in advance!

What have you tried so far?

ff community, google, youtube, chatgpt

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