Skip to content

API array response single element never returning #3743

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

Closed
2 tasks done
staplKody opened this issue Sep 4, 2024 · 11 comments
Closed
2 tasks done

API array response single element never returning #3743

staplKody opened this issue Sep 4, 2024 · 11 comments
Assignees
Labels
closed: other status: needs triage A potential issue that has not been confirmed as a bug. status: stale waiting for user response

Comments

@staplKody
Copy link

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

I have an API call that returns a JSON response with an array inside. When tested in my API setup, the response returns 200 and the expected array. In my component that is using this API, when an input is provided, an array is correctly acquired from the API's JSON path "ARRAY" and elements are produced in my listview.
However, if my array is only one element or zero elements, the logic following the API call in my component is never reached. It appears that the API call function is never returning, and so the application is perpetually awaiting the call.

Expected Behavior

I would expect the API function to return even if one element or zero elements are present in the array, and the component "contracts" that is being populated to match the returned array's size and elements.

Steps to Reproduce

  1. create a component with a text box, an icon to illustrate "loading", and a list widget.
    image

  2. Make an API call that returns a JSON response with an array inside.
    image

  3. On change of the textbox, set the component state "isLoading" to true which the icon has conditional visibility set to. Then make the API call, then set the API call's response.ARRAY (or whatever it is named in your API call's response definition) to a component called "contracts" as a defined data type. Last, set the "isLoading" state to false to make the icon hide again and indicate the process is finished.
    image

  4. Pass a value in the textbox that will return one or less items. (in my case passing in an exact contract number like 42133 results in one exact value, and anything longer than 5 characters will result in no items). Observe that the "isLoading" state never gets set to false and the "contracts" component state never gets set from this search (it retains its previous state before any text was changed in the textbox).

Reproducible from Blank

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

Bug Report Code (Required)

IT4kkcjfsMx2rsdY17X5be5Fv2UUQlAgTLIFse0aRR4jJYDyP5YAYM7SV0NKTfXnen9MM1agnj0G+vTNvt/1VO0pPT6aQNV70JVAZhfxZFO5VZfXCYewen8lTN1XI0iP37SRsBNCWLdtWF4c6k+pNa3qNleeY8aSfxBlZ7vfcPo=

Visual documentation

image

Environment

- FlutterFlow version: 4.1.83 
- Platform:Windows and browser
- Browser name and version: Chrome 128.0.6613.114
- Operating system and version affected: windows 11

Additional Information

No response

@staplKody staplKody added the status: needs triage A potential issue that has not been confirmed as a bug. label Sep 4, 2024
@staplKody
Copy link
Author

more context:

I've narrowed it down to how the JSON is being parsed by the code. This particular action is where it is hanging up.
image
and here is the generated code
image

@staplKody
Copy link
Author

I have a custom code solution that works as you would expect the generated code to behave. Feel free to use this to improve the generated code.

List? parseSearchContractsJSON(
dynamic jsonData) {
/// MODIFY CODE ONLY BELOW THIS LINE

//this function replaces the built in FF logic since it fails to return when jsonData.length <= 1
if (jsonData is List) {
// Map the List to List
return jsonData
.map((item) => SearchContractsResponseStruct.fromMap(item))
.cast() // Cast to the correct type
.toList();
} else {
// If jsonData is not a List, return an empty list
return [];
}

/// MODIFY CODE ONLY ABOVE THIS LINE
}

Replacing the built in actions with this custom function to set my "contracts" component state solved the issue. I am not entirely sure where the generated code is failing, and I am sure there may be some oversight in my function that needs to be considered for the generated function.

@paulperez-dev paulperez-dev self-assigned this Sep 5, 2024
Copy link
Collaborator

Hi @staplKody!

I believe the issue you're experiencing might be related to the custom code in your actions (see attachment). Could you review that code and see if it might be causing the problem?

image.png

@staplKody
Copy link
Author

That section of code is working as expected. The hangup only occured once the app attempted to parse the ARRAY property of my API response which occurs after that code expression is evaluated.

Copy link

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.

@staplKody
Copy link
Author

The issue is not resolved. There is a bug in the generated code shown above. I attached my solution that I implemented to resolve it for me, however I wouldn't consider this resolved unless FF has had an update modifying the generated code from the above action.

Copy link
Collaborator

Hi @staplKody,

Based on your code, it looks like nothing will happen if the response contains fewer than 3 elements. You might want to adjust for that condition.

@staplKody
Copy link
Author

The code you are referencing is on the input side. I won't run my queries until there are at least three characters inputted. What I am saying is the OUTPUT being 1 or 0 elements causes the issue.

Copy link

github-actions bot commented Oct 2, 2024

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.

Copy link
Collaborator

Hi @staplKody, could you please try replicating the issue on a blank project? This would help us isolate the cause and make it easier to identify a solution. Thanks for your assistance!

Copy link
Collaborator

We’re closing this issue as we haven’t heard back from you. If you’re still experiencing the problem, please feel free to submit a new issue.

Have a great day!

@paulperez-dev paulperez-dev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: other status: needs triage A potential issue that has not been confirmed as a bug. status: stale waiting for user response
Projects
None yet
Development

No branches or pull requests

2 participants