Display an API response with a custom function, display on a page and then pass to FireStore efficiently

Actions & Logic

I am using chatgpt API to make a call, display the response in a new page. Since the api call completion takes significant time I want to minimize the time caused by other processing like database write to a minimum. With that goal, I display the result on a page first and then record it. However as I do this I am re-processing the response at step #4 and #5, is there a way to avoid this re-processing (like I do for "prompt" in steps #1, #2, #3)? I can not select the screen #2 variable I assign the value in the firestore update document, it only shows the screen #1 variables. Do I need to create an App, is there a better way?

My current steps are

  1. Process the user inputs with custom function #1 and assign it to "prompt" page state variable

  2. Make an API call to chatgpt by using the "prompt" page state

  3. Create a Firestore Document by using the "prompt" page state

  4. Navigate to a new page and display the response after processing it with custom function #2

  5. Update the Firestore Document by re-processing the same response with the same custom function #2

What have you tried so far?

I have listed my alternative solution above. I have checked the state variable documentations

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