如何使用 getHttpsCallable 方法检索数据

Nel*_*eli 2 firebase flutter google-cloud-functions

我正在开发一个 flutter 应用程序,喜欢从 Firebase 云函数中获取数据。在插件 cloud_functions 0.2.0 中引入了 getHttpsCallable 方法,但没有任何地方描述如何使用它。

如何访问数据?

我尝试了以下操作,但它只打印“'HttpsCallable'的实例”

var result = CloudFunctions.instance.getHttpsCallable(
    functionName: 'addUser',
    parameters: {
      "name": 'blabla',
      "email": 'blabla'
    }
  );
print(result);
Run Code Online (Sandbox Code Playgroud)

Col*_*son 5

你可以awaitcall方法httpsCallable

示例应用程序具有以下用法:

                try {
                  final HttpsCallableResult result = await callable.call(
                    <String, dynamic>{
                      'message': 'hello world!',
                      'count': _responseCount,
                    },
                  );
                  print(result.data);
                  setState(() {
                    _response = result.data['repeat_message'];
                    _responseCount = result.data['repeat_count'];
                  });
                } on CloudFunctionsException catch (e) {
                  print('caught firebase functions exception');
                  print(e.code);
                  print(e.message);
                  print(e.details);
                } catch (e) {
                  print('caught generic exception');
                  print(e);
                }
Run Code Online (Sandbox Code Playgroud)