-
Notifications
You must be signed in to change notification settings - Fork 28
Description
Has your issue been reported?
- I have searched the existing issues and confirm it has not been reported.
- 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
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
- Create a data type (for example Order) having a field of datetime type.
- Create a cloud function which returns Order list.
- At cloud function return corresponding json data.
- Call cloud function.
- Check error at developer console of chrome (or running platform)
Reproducible from Blank
- The steps to reproduce above start from a blank project.
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
dart_sdk.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