Giter Club home page Giter Club logo

cloudbaseflutterdemo's Introduction

CloudbaseFlutter

在Flutter中使用云开发的云函数、云存储和云数据库能力的一个Demo。

视频教程

哔哩哔哩: https://www.bilibili.com/video/BV1RK411V7qc/
如果喜欢的话请一键三连呗♥♥♥

什么是云开发

Cloudbase
云开发 Cloudbase ,是Serverless云端一体化产品方案,是腾讯云为移动开发者提供的高可用、自动弹性扩缩的后端云服务,可用于开发多种端应用(小程序,公众号,Web 应用,Flutter 客户端等),达到一站式后台服务构建多端应用,帮助开发者统一构建和管理后端服务和后端云资源,避免了应用开发过程中参与繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。

任务介绍

以制作一个简单的在线执行代码的跨平台APP为例,通过使用云开发的 Flutter SDK ,介绍云开发在Flutter中的使用方法。 我们需要利用云开发的产品能力完成以下任务:

  1. 使用云函数实现调用执行代码API并返回结果
  2. 云存储中读取需要执行的代码
  3. 将调用云函数的执行结果储存到云数据库

本项目使用了 glot 在线执行代码的API,请先到官网(https://glot.io/) 进行账号注册,从而获取到自己的Api Token便于后续的操作。

准备工具

  • IDE: Intellij IDEA或Android Studio
  • Plugins: Flutter和Dart

注意事项

lib目录下的main.dart文件中,替换以下常量:

  • _envId: 填入您的云开发环境ID
  • _function: 填入您创建的云函数的名称
  • _collection: 填入您的云数据库集合名称
  • _fileId: 填入您上传到云存储的文件地址

云函数云存储使用到的代码可在function文件夹下找到,还需要将glot.js文件中请求头部中的认证字段替换为请填入您申请的glot API Token

cloudbaseflutterdemo's People

Contributors

0kirby avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cloudbaseflutterdemo's Issues

SDK登录失败,cloudbase论坛没人回复,您是否遇到相同问题?

_cloudFunction() async {
CloudBaseCore core =CloudBaseCore.init({
// 填写您的云开发 env
'env': '我的envid',
// 填写您的移动应用安全来源凭证
// 生成凭证的应用标识必须是 Android 包名或者 iOS BundleID
'appAccess': {
// 凭证
'key': '我的appkey',
// 版本
'version': '1'
},
'region': 'ap-guangzhou',//Google查到前端遇到相同问题,需要加的参数
// 请求超时时间(选填)
'timeout': 3000
});
// 获取登录状态
CloudBaseAuth auth = CloudBaseAuth(core);
CloudBaseAuthState authState = await auth.getAuthState();
// 唤起匿名登录
if (authState == null) {
await auth.signInAnonymously().then((success) {
// 登录成功
print(success);
}).catchError((err) {
// 登录失败
print(err);
});
}
CloudBaseFunction cloudbase = CloudBaseFunction(core);
Map<String, dynamic> data = {'code': _code, 'stdin': _stdin};
CloudBaseResponse res = await cloudbase.callFunction(_function, data);
setState(() {
_output = res.data;
});
}
匿名登录报问题:
flutter: CloudBaseError [INVALID_REGION]: Environment create in ap-guangzhou cannot access in ap-shanghai
应该是SDK请求参数的问题
我目前使用的是免费版套餐,只有广州一个环境

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.