在 Flutter 中使用 Firebase Cloud Functions 的方法是什么。

Sea*_*uzz 5 firebase flutter google-cloud-functions

我一直在寻找如何使用颤振应用程序实现 firebase 功能。似乎没有可用的 SDK(还)。我也尝试将 gradle 依赖项添加implementation 'com.google.firebase:firebase-functions:15.0.0'到我的,app/build.gradle但这会导致构建错误。

有没有人做过有效的实现?我找不到有关如何处理凭据和数据传输以构建我自己的 Firebase 函数调用的任何文档。

我已经创建了一个粗略的轮廓,说明我认为这是如何工作的,但可能有偏差。

Future<dynamic> updateProfile(String uid, AccountMasterViewModel avm) async {

    Uri uri = Uri.parse(finalizeProfileFunctionURL);
    var httpClient = new HttpClient();
    String _result = '';

    try {
      return await httpClient
        .postUrl(uri)
        .then((HttpClientRequest request) {
          return request.close();
          // authentication??
          // Fields and data??
        })
        .then((HttpClientResponse response) async {
            print(response.transform(new Utf8Codec().decoder).join());
            if (response.statusCode == HttpStatus.OK) {
              String json = await response.transform(new Utf8Codec().decoder).join();
              _result = jsonDecode(json);
              // Do some work
              return json;
            } 
            else {
              return ':\nHttp status ${response.statusCode}';
            }
          });
        }
        catch (exception) {
          return 'Failed ' + exception.toString();
        }
      }
Run Code Online (Sandbox Code Playgroud)

我希望能够发送一个对象,比如

{
    accountID: src.accountID, 
    accountName: src.name,
    accountImg: src.image
}
Run Code Online (Sandbox Code Playgroud)

然后处理响应。但正如我所说,我找不到任何关于如何做到这一点的工作示例或教程。执行此客户端大小并直接与数据库对话是相当简单的,但是,需要对客户端隐藏验证和数据组件,因此云函数是我想要执行此操作的方式。

ujj*_*ali 5

是的,这里有一个 cloud_function 包:https ://pub.dartlang.org/packages/cloud_function 。

以便调用您可以调用的函数

CloudFunctions.instance.call(
                    functionName: 'yourCloudFunction',
                    parameters: <String, dynamic>{
                      'param1': 'this is just a test',
                      'param2': 'hi there',
                    },
                  );
Run Code Online (Sandbox Code Playgroud)


Man*_*ans 2

这是一个关于 flutter 中云函数的很好的教程,它帮助了我:

https://rominiirani.com/tutorial-flutter-app-powered-by-google-cloud-functions-3eab0df5f957