跳到主要内容

云函数

callFunction​

Future<FunctionResponse> app.callFunction({
required String name,
FunctionType type = FunctionType.function,
Map<String, dynamic>? data,
HttpMethod method = HttpMethod.post,
String path = '/',
Map<String, String>? header,
bool parse = true,
})

调用云函数。支持基础云函数和函数型云托管两种类型的统一调用。

参数

name
String

函数/服务名称

type
FunctionType

调用类型:FunctionType.function(默认)/ FunctionType.cloudrun

data
Map<String, dynamic>?

请求数据

method
HttpMethod

HTTP 方法(仅 cloudrun 类型有效,默认 POST)

path
String

HTTP 路径(仅 cloudrun 类型有效,默认 /)

header
Map<String, String>?

HTTP 请求头(仅 cloudrun 类型有效)

parse
bool

是否解析返回对象(仅 function 类型有效,默认 true)

返回

Future
FunctionResponse

示例

final result = await app.callFunction(
name: 'myFunction',
data: {'action': 'getUserList', 'pageSize': 10},
);

if (result.isSuccess) {
print('执行结果: ${result.result}');
} else {
print('执行失败: ${result.message}');
}