Using this code snippet to call httpsCallable cloud function on firebase:
@override
Future<InitializePickupRequestCommandResult> initialize(
ClientEntity client,
PositionEntity location,
PositionEntity destination, {
required bool isVehicleEmpty,
}) async {
final data = InitializePickupRequestCommand.from(
client,
location,
destination,
isVehicleEmpty: isVehicleEmpty,
).toJson();
final name = describeEnum(CloudFunctionNames.initializePickupRequest);
final initializePickupRequest = backend.httpsCallable(name);
final result = await initializePickupRequest.call(data);
return InitializePickupRequestCommandResult.from(
result.data as Map<String, dynamic>,
);
}
data object holds all required data for the CF to perform the operation, it is of type Map<String, dynamic>.
Map<String, dynamic> toJson() => {
"clientId": clientId,
"clientLat": clientLat,
"clientLng": clientLng,
"vehicleType": vehicleType,
"isVehicleEmpty": isVehicleEmpty,
"location": {
"lat": clientLat,
"lng": clientLng,
},
"destination": {
"placeId": destination.id,
"zip": destination.zip,
"city": destination.city,
"searchString": destination.searchString,
"lat": destination.lat,
"lng": destination.lng,
},
};
Problem
every time when trying to call the CF, it throws this exception:
_AssertionError ('package:cloud_functions/src/https_callable.dart': Failed assertion: line 33 pos 12: '_debugIsValidParameterType(parameters)': is not true.)
What i tried
using these as params:
data as Map<String, dynamic>{...data}<String, dynamic>{...data}
Tried {"dummy": "data"} as a param and the CF was executed normally. don't know why!
So how parameters should be passed to https callable cloud function?
"lng": clientLng,,"lng": destination.lng,and the last},. Try removing them. It's ok in Flutter but maybe it means an invalid JSON.jsonEncode(data)before submitting.