Giter Club home page Giter Club logo

cloudbase-flutter-sdk's Introduction

CloudBase Flutter SDK 是腾讯云云开发(Tencent Cloud Base)多端 SDK 中的一员,主要支持 Flutter 框架下使用云开发能力。CloudBase 提供 Serverless 云端一体化服务,使用 CloudBase,可以快速构建小程序、移动App、网页等应用。

Flutter 插件

CloudBase Flutter SDK 提供一系列插件,可以根据场景按需加载。

Plugin Version 文档 描述
cloudbase_core pub package CloudBase Core 核心库,初始化环境等
cloudbase_auth pub package CloudBase Auth 鉴权库,支持微信登录、自定义登录、匿名登录等
cloudbase_function pub package CloudBase Function 支持云函数能力
cloudbase_database pub package CloudBase Database 支持文档型数据库能力
cloudbase_storage pub package CloudBase Storage 支持对象存储能力

快速开始

1. 配置云开发资源

腾讯云云开发控制台 创建环境(已有环境可跳过)。

用户管理页面中,点击“登录设置”,然后启用匿名登录

新建云函数 sum

sum 云函数中添加代码。

"use strict";
exports.main = (event, context, callback) => {
  callback(null, event.a + event.b);
};

2. 创建 Flutter 项目

$ flutter create cloudbase_demo
$ cd cloudbase_demo

3. 添加 CloudBase 插件依赖

在项目的 pubspec.yaml 文件中添加 dependencies

dependencies:
  cloudbase_core: ^0.0.2
  cloudbase_auth: ^0.0.2
  cloudbase_functions: ^0.0.1

pub 安装依赖。

$ flutter pub get

4. 调用云函数

在项目的 lib/main.dart 文件中进行匿名登录,并调用运用 sum 云函数。

import 'package:cloudbase_auth/cloudbase_core.dart';
import 'package:cloudbase_core/cloudbase_autj.dart';
import 'package:cloudbase_function/cloudbase_function.dart';

// 初始化 CloudBase
CloudBaseCore core = CloudBaseCore.init({
    // 填写你的云开发 env
    'env': 'your-env-id'
});

// 获取登录状态
CloudBaseAuthState authState = await auth.getAuthState();

// 唤起匿名登录
if (authState == null) {
    await auth.signInAnonymously().catchError((err) {
        // 处理匿名登录错误
        print(e);
    });
}

// 调用云函数
CloudBaseFunction func = CloudBaseFunction(core);
Map<String, dynamic> data = {'a': 1, 'b': 2};
CloudBaseResponse res = await func.callFunction('sum', data);
// 打印云函数结果
print(res);

cloudbase-flutter-sdk's People

Contributors

lt5c avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.