Skip to content

Component var updates in streaming API inside action block prepends _model. #5580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
Jotte92 opened this issue Mar 19, 2025 · 5 comments
Open
2 tasks done
Assignees
Labels

Comments

@Jotte92
Copy link

Jotte92 commented Mar 19, 2025

Can we access your project?

  • I give permission for members of the FlutterFlow team to access and test my project for the sole purpose of investigating this issue.

Current Behavior

Streaming API call that is inside a component level action block will prepend "_model." to the function.

(onMessageInput) async { _model.updateVariableAtIndex(

This does not throw an error in Flutterflow but it will when pulling to VS code.

Expected Behavior

Does not need to prepend "_model." as its already inside the model.

Steps to Reproduce

  1. Create streaming API request
  2. Create component state variable
  3. Create component level actionblock
  4. Add API call to action block and update the variable onMessage

Reproducible from Blank

  • The steps to reproduce above start from a blank project.

Bug Report Code (Required)

ITFfksmBw41Pm9tc1r6Jb8BGnmYWH0ccTOURiO0bFDsdF4iuPOxzacnCXE9tYN+rTAhfKEWJhmoywdbLhtjlNPUoORKaRa0/+s5ubTzzWni/aoSxBsyNOHZQEeNWGU+P07ejuQl+ItducnMsw06uBPKicHbXHqX7Zwh9f6PHaOI=

Visual documentation

Image

Environment

- FlutterFlow version: v5.2.9
- Platform: VS code
- Browser name and version: Brave Version 1.75.181
- Operating system and version affected: MacOS 15.3.1

Additional Information

No response

@Jotte92 Jotte92 added the status: needs triage A potential issue that has not been confirmed as a bug. label Mar 19, 2025
@Alezanello Alezanello self-assigned this Mar 20, 2025
Copy link
Collaborator

Hello! 😊

One important thing to keep in mind is that Action Blocks (App Block or Component Block) don’t have direct access to the model they are implemented in. This means that trying to update a component’s state directly from an Action Block will likely result in failure.

Instead, you might consider using AppState, as it doesn’t require direct access to any specific model and can help you achieve the desired behavior.

@Alezanello Alezanello removed the status: needs triage A potential issue that has not been confirmed as a bug. label Mar 20, 2025
@Alezanello Alezanello added the status: not a bug This is not a bug. label Mar 20, 2025 — with Linear
@Jotte92
Copy link
Author

Jotte92 commented Mar 20, 2025

Hello Alezanello,

Thank you for your response! Sorry if i'm misunderstanding how states are handled.

My issue seems to be coming from trying to update a component state that is a list of a custom data type from within a streaming API call in the block, flutterflow is prepending _model. to the function when it should not be. I think this may be specific to streaming API calls which i'm trying to do.

Please take a look at my code to see.
ITFfksmBw41Pm9tc1r6Jb8BGnmYWH0ccTOURiO0bFDsdF4iuPOxzacnCXE9tYN+rTAhfKEWKr3wHzN7Gj+L+GvoFPQWVGIRe/7lcVgvMQnO/aoSxBsyNOHZQEeNWGU+P07ejuQl+ItducnMsw06uBPKicHbXHqX7Zwh9f6PHaOI=

If I download my code and remove the _model. manually, this solves the problem and my code will run, updating the component state. However, I get UI refresh issues, only the first chunk will display on my screen the others don't update, although all chunks are processed and stored in component state, so it can be accessed.

I have now moved all the logic to AppState, which has solved my issue as you suggested.

Copy link
Collaborator

Hello!!

Could you try instead of using the "As Data Type" option directly. select the "Server Sent Event Data JSON" option from the "Response Stream Message Options" dropdown, then select "To Data Type" and then select the data type.

try to save it this way!

@Jotte92
Copy link
Author

Jotte92 commented Mar 25, 2025

Hey,

This is basically how I do it, i'm streaming a chatGPT response into a "ChatItem" data type (which contains a 'content' field) from the server sent event JSON as a string and appending it to the previous chunk with combine text.

Because i'm updating a component variable that is a list of ChatItem data on each chunk flutterflow uses the _model.updateVarAtIndex function, which would be correct if the API call was in the widget, but because it's in the component block it shouldn't be using _model. it has direct access to updateVarAtIndex.

I really think this is a bug, as VS code picks up the error but flutterflow doesn't, and if I remove _model. it runs.

@Jotte92 Jotte92 changed the title Component var updates in streaming API inside action block append _model. Component var updates in streaming API inside action block prepends _model. Mar 26, 2025
Copy link

github-actions bot commented Apr 2, 2025

This issue is stale because it has been open for 7 days with no activity. If there are no further updates, a team member will close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants