FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
120 stars 18 forks source link

DateTime error at Cloud functions response to data type conversion. #2559

Open gokcer opened 6 months ago

gokcer commented 6 months ago

Has your issue been reported?

Current Behavior

When we defined a cloud function return a data type, if data type contains datetime field, json response of cloud function is not converted to datetime.

Expected Behavior

Json response of cloud function should be correctly converted to datetime like string or number fields.

Steps to Reproduce

  1. Create a data type (for example Order) having a field of datetime type.
  2. Create a cloud function which returns Order list.
  3. At cloud function return corresponding json data.
  4. Call cloud function.
  5. Check error at developer console of chrome (or running platform)

Reproducible from Blank

Bug Report Code (Required)

IT4olPLq25NIseFE7q6JcMdVryQQNkA4arsWm8pOGDsdF4iuPOxzafTsZRFCTubidHxhKEWKoEcHw+jwvuOTUcc3AE6CRqk71c5qcjvxeHi/aoSUDJGCRmhfBdpMGGKF0p6RmCNAOvZ2Sl0j3TmHevCQYB/vQ5P4Zwh9f6PHaOI=

Context

I am trying to return data type containing a datetime field from cloud functions.

Visual documentation

dartsdk.js:11914 Uncaught (in promise) Error: TypeError: "2024-03-19T10:07:50.655268+00:00": type 'String' is not a subtype of type 'DateTime?' at Object.throw\\ \[as throw\] (dart_sdk.js:11914:11) at Object.\_failedAsCheck (dart_sdk.js:24571:15) at dart_rti.Rti.new.\_generalNullableAsCheckImplementation (dart_sdk.js:24564:14) at dart_rti.Rti.new.\_installSpecializedAsCheck (dart_sdk.js:24509:24) at OrderStruct.fromMap (order_struct.dart:39:28) at MappedListIterable.new. (home_page_widget.dart:109:51) at MappedListIterable.new.elementAt (dart_sdk.js:34795:25) at ListIterator.new.moveNext (dart_sdk.js:34596:55) at JsIterator.next (dart_sdk.js:14044:21) at List.of (dart_sdk.js:139635:18) at MappedListIterable.new.toList (dart_sdk.js:34404:30) at home_page_widget.\_HomePageWidgetState.new. (home_page_widget.dart:109:60) at Generator.next () at dart_sdk.js:49722:33 at \_RootZone.runUnary (dart_sdk.js:49577:59) at \_FutureListener.thenAwait.handleValue (dart_sdk.js:44704:29) at handleValueCallback (dart_sdk.js:45304:49) at \_Future.\_propagateToListeners (dart_sdk.js:45342:17) at \[\_completeWithValue\] (dart_sdk.js:45183:23) at async.\_AsyncCallbackEntry.new.callback (dart_sdk.js:45217:35) at Object.\_microtaskLoop (dart_sdk.js:50026:13) at \_startMicrotaskLoop (dart_sdk.js:50032:13) at dart_sdk.js:45573:9

Additional Info

According to debugging using exported code, problem is caused by fromMap function of generated (DataType)Struct.dart class. It does not support parsing DateTime from string and expects an object but cloud function (and other systems) return datetime data as string.

static OrderStruct fromMap(Map data) => OrderStruct( name: data\['name'\] as String?, total: castToType(data\['total'\]), date: data\['date'\] as DateTime?, <------------ Problematic line. Maybe should call DateTime.parse() instead of cast if value is string since json responses return string for datetime fields. );

Environment

- FlutterFlow version: 4.1
- Platform: Any platform
- Browser name and version: Any
- Operating system and version affected: Any
github-actions[bot] commented 6 months 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.

sebasortiz-dev commented 6 months ago

Im having the same issue

ignalauret commented 5 months ago

Hey @gokcer thanks for your report. Could you share me the code of the Cloud Function that you are using so I can check out?

gokcer commented 5 months ago
Screen Shot 2024-04-11 at 22 36 54

Sure @ignalauret

Here it is:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
// To avoid deployment errors, do not call admin.initializeApp() in your code

exports.orders = functions.region('us-west1').https.onCall(
  (data, context) => {
    // Write your code below!

    // Write your code above!
      return [{
        "id": 1,
        "date": "2024-03-19T10:07:50.655268+00:00",
        "name": "John Due",
        "total": 10
    }];
  }
);
ignalauret commented 5 months ago

Hey @gokcer thanks for the code. I was able to replicate the issue, and I'm not able to parse the Date as a String (like you have it) nor as a js Date object.
I'm sending a ticket to the Technical team to see if this is a bug, or if there is another way of encoding the dates that you should do on the function.
They will keep you updated on this thread, have a great day!

gokcer commented 4 months ago

Hi. Are there any progress about this bug? It blocks our implementations using DateTime.

Best regards..

luis-caf commented 3 weeks ago

Im having the same issue