在Flutter中使用Firebase云功能的方法是什么?

问题描述 投票:1回答:3

我一直在搜索如何使用flutter应用程序实现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();
        }
      }

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

{
    accountID: src.accountID, 
    accountName: src.name,
    accountImg: src.image
}

然后处理响应。但正如我所说,我找不到任何有关如何执行此操作的示例或教程。执行此客户端大小并直接与数据库通信相当简单,但是,需要从客户端隐藏验证和数据组件,因此云功能是我希望这样做的方式。

firebase google-cloud-functions flutter
3个回答
3
投票

是的,这里有一个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',
                    },
                  );

1
投票

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

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


1
投票

云功能可以由实时数据库,Firestore或数据存储区中的数据更改触发器以及身份验证触发器触发。

你可以坚持下去

{
    accountID: src.accountID, 
    accountName: src.name,
    accountImg: src.image
}

到数据库并注册在插入,更新或删除特定路径的数据时运行云功能的触发器。

https://firebase.google.com/docs/functions/firestore-events

© www.soinside.com 2019 - 2024. All rights reserved.