FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
117 stars 19 forks source link

API array response single element never returning #3743

Open staplKody opened 2 weeks ago

staplKody commented 2 weeks ago

Can we access your project?

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

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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.

github-actions[bot] commented 1 week ago

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 commented 1 week ago

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.

paulperez-dev commented 2 days ago

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 commented 2 days ago

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.