Skip to content
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

"null" numerics in API JSON results do not map correct to data types #5454

Open
2 tasks done
d6p2b opened this issue Feb 19, 2025 · 1 comment
Open
2 tasks done

"null" numerics in API JSON results do not map correct to data types #5454

d6p2b opened this issue Feb 19, 2025 · 1 comment
Assignees
Labels
status: not a bug This is not a bug.

Comments

@d6p2b
Copy link

d6p2b commented Feb 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

FlutterFlow does not correctly handle the mapping of JSON objects to data types (structs) when the data type has numeric (integer or double) fields and the JSON includes null values as empty strings. The implementation of castToType() in ./lib/flutter_flow/flutter_flow_util.dart doesn't anticipate an empty string in the case of a double or integer resulting in an exception when it tries to return the empty string as one of the numeric types.

Expected Behavior

Change castToType() to check for empty strings in the case of integers and doubles and return a null value.

Steps to Reproduce

  1. Create a new project.
  2. Create a data type with numeric fields.
  3. Create an API call which returns a JSON string containing null values for the numeric fields.
  4. Create a new page.
  5. Add a button.
  6. Add an action to the button to trigger the API and map the resulting JSON to the data type.

The mapping will never succeed because an exception will be raised in castToType().

Reproducible from Blank

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

Bug Report Code (Required)

IT48k8jq349Psbxc1pPpbfowpDwsQ3k7UL8ZkOpuZxI8J5zKB+wAYvf7P1FWTL3mdwhUf0yWimM0xvfqktntMu4EORSWQLpSzqtiVQnJUlK5bIyLPqiRfW1fN8FPCUCB4baFoSRAOtdpSEIF3U2MGvO+dCjUNqb2NmosROSbLdeK2SrDX1iXc2URm05KZDPz

Visual documentation

Image Image Image

Environment

- FlutterFlow version: 5.2.2 (released February 19, 2025)
- Platform: macOS
- Browser name and version:
- Operating system and version affected:

Additional Information

Added the following code to both the int and double cases in the implementation of castToType() in lib/flutter_flow/flutter_flow_util.dart and all my problems went away.

// Handle null values (empty strings)
if ((value is String) && (value == '')) return null;
@d6p2b d6p2b added the status: needs triage A potential issue that has not been confirmed as a bug. label Feb 19, 2025
Copy link
Collaborator

Hello!

In this case, the issue is related to the data type configuration. You have the field set as Int in FlutterFlow, while the JSON response is returning a String. It’s not returning null; instead, it's returning an empty string (''). This isn't a FlutterFlow issue—it's a mismatch between the data type and the response.

I recommend either:

Modifying the API response to return the value as an integer.

OR

Adjusting the DataType in FlutterFlow to String. After parsing, you can handle any empty string validations directly within FlutterFlow as needed.

This should help resolve the issue. Let me know if you need further assistance!

@Alezanello Alezanello self-assigned this Feb 19, 2025
@Alezanello Alezanello removed the status: needs triage A potential issue that has not been confirmed as a bug. label Feb 19, 2025
@Alezanello Alezanello added the status: not a bug This is not a bug. label Feb 19, 2025 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: not a bug This is not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants