Describe the bug
When calling an onCall Cloud Function from Flutter a PlatformError is thrown indicating that the data is not properly formatted.
PlatformException(3840, The data couldn’t be read because it isn’t in the correct format., null)
To Reproduce
Run the provides example in the docs: https://github.com/FirebaseExtended/flutterfire/blob/master/packages/cloud_functions/cloud_functions/example/lib/main.dart
```
..
final HttpsCallable callable = CloudFunctions.instance
.getHttpsCallable(functionName: 'repeat')
..timeout = const Duration(seconds: 30);
...
..
final HttpsCallableResult result = await callable.call(
'message': 'hello world!',
'count': _responseCount,
},
);
..
```
Hi @cornetthomas
can you please provide your flutter doctor -v ,
your flutter run --verbose
and your pubspec.yaml
Thank you
same issue here
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76,
locale en-US)
• Flutter version 1.12.13+hotfix.8 at /users/user/flutter
• Framework revision 0b8abb4724 (5 weeks ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/user/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_152-release-1248-b01)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[!] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build
1.8.0_152-release-1248-b01)
[✓] VS Code (version 1.43.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1
[✓] Connected device (1 available)
• iPhone 11 Pro Max • 846E2381-9812-450A-9E26-EBB557CFD139 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
! Doctor found issues in 2 categories.
========================================================
and here is my pubspec.yaml
name: projectX
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
provider:
google_fonts:
firebase_core:
firebase_auth:
firebase_database:
flutter_swiper:
cloud_functions: 0.4.1+6
cloud_functions_platform_interface:
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
module:
androidX: true
flutter:
uses-material-design: true
assets:
- images/
- images/cards/
@iapicca @cornetthomas looks like this is not a bug, result.success(task.getResult().getData());
expects your cloud function to return json response with the result in data propetry or bind your function at functions.https.onCall instead of functions.https.onRequest
Hi @cornetthomas
does @krishkg solution works for you?
thank you both
Leaving open to track, this can potentially be handled on native to avoid crashes.
I'm getting this issue too, and I'm already defining my cloud function using functions.https.onCall as @krishkg suggests. However, the cloud function logs indicate that my call doesn't even make it to Firebase as it doesn't register the function as being triggered.
Versions:
firebase_core: ^0.4.4+3
cloud_functions: ^0.5.0
Flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[✓] Android Studio (version 3.6)
[✓] Connected device (1 available)
Nevermind, I've found a fix. The issue is because I started specifying the region in-which I want my cloud function to run, but didn't realise that I had to specify that when calling the function. See here.
Perhaps the output of the error could be improved?
Or the docs for the call function in HttpsCallable could be improved to state that if you are specifying a region other than the default us-central1 then you must also specify it on the client side
I'm Getting the same issue.
Future<String> getPassword() async {
final HttpsCallable callable = CloudFunctions.instance
.getHttpsCallable(functionName: 'getPassword')
..timeout = const Duration(seconds: 30);
try {
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
"pwLength": 10,
"useSymbols": true,
},
);
print(result.data['password']);
return result.data['password'];
} on CloudFunctionsException catch (e) {
print('caught firebase functions exception');
print('Code: ${e.code}\nmessage: ${e.message}\ndetails: ${e.details}');
return '${e.details}';
} catch (e) {
print('caught generic exception');
print(e);
return 'caught generic exception\n$e';
}
}
My cloud function logs tell me that both the type and value of the parameters are null. Any help?
Most helpful comment
Nevermind, I've found a fix. The issue is because I started specifying the region in-which I want my cloud function to run, but didn't realise that I had to specify that when calling the function. See here.
Perhaps the output of the error could be improved?
Or the docs for the
callfunction inHttpsCallablecould be improved to state that if you are specifying a region other than the defaultus-central1then you must also specify it on the client side