Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public void onMethodCall(MethodCall call, final Result result) {
switch (call.method) {
case "CloudFunctions#call":
String functionName = call.argument("functionName");
String region = call.argument("region");
HttpsCallableReference httpsCallableReference =
FirebaseFunctions.getInstance().getHttpsCallable(functionName);
FirebaseFunctions.getInstance(region).getHttpsCallable(functionName);
Map<String, Object> parameters = call.argument("parameters");
httpsCallableReference
.call(parameters)
Expand Down
54 changes: 27 additions & 27 deletions packages/cloud_functions/ios/Classes/CloudFunctionsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ - (instancetype)init {
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"CloudFunctions#call" isEqualToString:call.method]) {
NSString *functionName = call.arguments[@"functionName"];
NSString *region = call.arguments[@"region"];
NSObject *parameters = call.arguments[@"parameters"];
[[FIRFunctions functions]
callFunction:functionName
withObject:parameters
completion:^(FIRHTTPSCallableResult *callableResult, NSError *error) {
if (error) {
FlutterError *flutterError;
if (error.domain == FIRFunctionsErrorDomain) {
NSDictionary *details = [NSMutableDictionary dictionary];
[details setValue:[self mapFunctionsErrorCodes:error.code] forKey:@"code"];
if (error.localizedDescription != nil) {
[details setValue:error.localizedDescription forKey:@"message"];
[[[FIRFunctions functionsForRegion:region] HTTPSCallableWithName:functionName]
callWithObject:parameters
completion:^(FIRHTTPSCallableResult *callableResult, NSError *error) {
if (error) {
FlutterError *flutterError;
if (error.domain == FIRFunctionsErrorDomain) {
NSDictionary *details = [NSMutableDictionary dictionary];
[details setValue:[self mapFunctionsErrorCodes:error.code] forKey:@"code"];
if (error.localizedDescription != nil) {
[details setValue:error.localizedDescription forKey:@"message"];
}
if (error.userInfo[FIRFunctionsErrorDetailsKey] != nil) {
[details setValue:error.userInfo[FIRFunctionsErrorDetailsKey]
forKey:@"details"];
}
flutterError =
[FlutterError errorWithCode:@"functionsError"
message:@"Firebase function failed with exception."
details:details];
} else {
flutterError = [FlutterError errorWithCode:nil
message:error.localizedDescription
details:nil];
}
if (error.userInfo[FIRFunctionsErrorDetailsKey] != nil) {
[details setValue:error.userInfo[FIRFunctionsErrorDetailsKey] forKey:@"details"];
}

flutterError =
[FlutterError errorWithCode:@"functionsError"
message:@"Firebase function failed with exception."
details:details];
result(flutterError);
} else {
flutterError = [FlutterError errorWithCode:nil
message:error.localizedDescription
details:nil];
result(callableResult.data);
}
result(flutterError);
} else {
result(callableResult.data);
}
}];
}];
} else {
result(FlutterMethodNotImplemented);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/cloud_functions/lib/cloud_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ class CloudFunctions {
/// Executes this Callable HTTPS trigger asynchronously.
///
/// @param functionName The name of the callable function being triggered.
/// @param region The region where the callable function being triggered. Default: us-central1.
/// @param parameters Parameters to be passed to the callable function.
Future<dynamic> call(
{@required String functionName, Map<String, dynamic> parameters}) async {
{@required String functionName,
String region = 'us-central1',
Map<String, dynamic> parameters}) async {
try {
final dynamic response =
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
// https://github.com/flutter/flutter/issues/26431
// ignore: strong_mode_implicit_dynamic_method
await channel.invokeMethod('CloudFunctions#call', <String, dynamic>{
'functionName': functionName,
'region': region,
'parameters': parameters,
});
return response;
Expand Down
12 changes: 12 additions & 0 deletions packages/cloud_functions/test/cloud_functions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,37 @@ void main() {
.call(functionName: 'qux', parameters: <String, dynamic>{
'quux': 'quuz',
});
await CloudFunctions.instance
.call(functionName: 'buz', region: 'us-east1');
expect(
log,
<Matcher>[
isMethodCall(
'CloudFunctions#call',
arguments: <String, dynamic>{
'functionName': 'baz',
'region': 'us-central1',
'parameters': null,
},
),
isMethodCall(
'CloudFunctions#call',
arguments: <String, dynamic>{
'functionName': 'qux',
'region': 'us-central1',
'parameters': <String, dynamic>{
'quux': 'quuz',
},
},
),
isMethodCall(
'CloudFunctions#call',
arguments: <String, dynamic>{
'functionName': 'buz',
'region': 'us-east1',
'parameters': null,
},
),
],
);
});
Expand Down