Creating then Querying the same Firestore Document on the Same Page

Actions & Logic

What I’m trying to do:
On page load, I want to create a Firestore document (Submission) and then immediately use that document on the same page to display/update fields. I also need to pass the document reference to future pages.

What’s going wrong:
Whenever I try to do both the creation and the query on the same page, the app crashes. I am guessing it's because the query is happening before the document is created.

Goal:
I just want to create the document on page load, query and use it immediately on that page, and later pass the ref along to other screens.

I’m open to any suggestions.

Thanks in advance! 🙏

What have you tried so far?
  1. Creating the document in the page load action and setting it to a page state variable (e.g., submissionRef). Then trying to use that state ref in a query. Crashes.

  1. Using conditional visibility in the widget tree so it is only visible if the document is created submissionRef != null. Still crashes.

  2. Creating the document on a previous page, then passing it to this one through a parameter and querying it. This works, but I run into other issues. This approach I stored the parameter in the navigation bar. The parameter is then passed to EVERY page with the nav bar in the app and I don't want that.

  3. Trying “Set Page State” → Value: Create Document → Document Reference and updating the state before any queries run. Didn’t help.

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