1. The background

CloudBase provides a powerful one-stop back-end service, and has cooperated with the wechat team to launch “Mini Program · Cloud Development”, serving more than 500,000 developers.

We also want to combine cloud development with Flutter to achieve an ultimate Flutter cloud integrated workflow. Previously, there have been some explorations:

  • Implement the Flutter SDK for cloud development

    A Flutter client can use the cloud to develop the Flutter SDK and call backend resources such as cloud functions, cloud databases, and cloud storage. However, cloud functions do not support the DART runtime, so only BAAS capability, not FAAS capability.

  • Deploy the Dart Server in the Serverless cloud application

    The underlying Serverless cloud application is a container that supports any language, so dart Server cloud applications can be deployed, improving cloud development capabilities. However, there are also requirements for developers to understand container services, write dockfiles, and select the Dart Server framework.

To maximize cloud integration, we developed CloudBase Framework, an integrated application development and deployment tool that can create and deploy DART Server applications with one click and supports declarative cloud resource creation.

CloudBase Framework has been open source on Github, welcome everyone to project a Star

2. What does CloudBase Framework For Flutter do?

2.1 Quickly Create and Deploy the Dart Server

With the CloudBase Framework, you can develop an o&M free, automatically scalable, high-performance DART Server application with just a few lines of command.

Install the CLI tool
npm install -g @cloudbase/cli

# login CloudBase
cloudbase login

Initialize the DART Server application
cloudbase init --template dart

Enter the dart Server application root directory
cd dartapp

Deploy dart Server to the cloud
cloudbase framework:deploy
Copy the code

The deployment was successful

Access services: test-docker-117e45.service.tcloudbase.com/dartapp

2.2 Develop simple API interfaces

Within the dart Server application you are creating, open the lib/channel.dart file and develop your API in the entryPoint() function.

@override
Controller get entryPoint {
  final router = Router();

  router.route("/example").linkFunction((request) async {
    return Response.ok({"key": "value"});
  });

  return router;
}
Copy the code

After redeploying the application, request the subpath/Example

2.3 Cloud database out of the box

We’ve integrated the cloud database with the Dart Server application and can call the database with a simple code change.

The same cloud database can also be called on the client side with the Flutter SDK

Initialize the cloud database in the prepare() function of the lib/channel.dart file.

@override
Future prepare() async {
  /// Other initialization code./// Initialize the cloud database
  database = CloudBaseDatabase(CloudBaseCore.init({
    /// ID of cloud development environment
    'env': 'your-env-id'./// Tencent Cloud API fixed key pair
    /// Access path: https://console.cloud.tencent.com/cam/capi
    'secretId': 'your-secretId'./// Same as above
    'secretKey': 'your-secretKey'
  }));
}
Copy the code

Develop a database interface in the entryPoint() function.

@override
Controller get entryPoint {
  final router = Router();

  /// Use the cloud database in the request
  /// Cloud database detailed documentation refer to: https://docs.cloudbase.net/api-reference/flutter/database.html
  router.route("/user").linkFunction((request) async {
    try {
      /// The User collection has been declaratively created during dart Server deployment
      final res = await database.collection('user').count();

      /// Handling errors
      if(res.code ! =null) {
        return Response.serverError(
            body: {"code": res.code, "message": res.message});
      }

      /// Back to the package
      return Response.ok({"user_count": res.total});
    } catch (err) {
      returnResponse.serverError(body: err); }});return router;
}
Copy the code

After redeploying the application, request the subpath /user

2.4 Creating Cloud Resources declaratively

In the application configuration file cloudBaserc.json, two plug-ins are declared: server and DB. So in one-click deployment, you create both the Dart Server application and the database set user on which the application depends.

{
  "envId": "env-123"."framework": {
    "name": "aqueduct-starter"."plugins": {
      "server": {
        "use": "@cloudbase/framework-plugin-dart"."inputs": {
          "serviceName": "dartapp"."servicePath": "/dartapp"."localPath": ". /"}},"db": {
        "use": "@cloudbase/framework-plugin-database"."inputs": {
          "collections": [{"collectionName": "user"."description": "User set"."aclTag": "PRIVATE"}]}}}}}Copy the code

2.5 more

  • You can quickly deploy the same application to multiple environments (experience, pre-delivery, production) by switching between template variables and modes.
  • Approved for publication through Coding CI/CD

See the technical documentation cloudbase.net for more

3. Benefits of CloudBase Framework

3.1 Cost reduction and efficiency increase

Flutter developers can use the CloudBase Framework to develop API services to complete the closed loop of front-end and back-end services, and have the ability to automatically expand and shrink without operation and maintenance.

R&d cost of Flutter cloud integration = traditional mode R&D cost – operation and maintenance cost – front-end and back-end joint adjustment cost – idle resource cost

3.2 cloud native

“Flutter X CloudBase Framework” is a future-oriented solution based on the idea of cloud native, which is the best practice for clients to access the cloud.

4. CloudBase Framework vision

4.1 Be part of the Flutter development workflow

Dart Server applications can be quickly developed and launched with the Help of the CloudBase Framework. Flutter developers can complete the closed loop of the front-end and back-end businesses themselves.

Further, it is hoped that there will be deeper integration with the Flutter client project as part of the Flutter development workflow.

4.2 Help more teams to get on the cloud

CloudBase Framework is an integrated development and deployment tool for cloud development. It can help developers quickly build applications on the cloud. In the future, it will continue to optimize the experience, support more functions and help more teams to access the cloud.

At present, multiple teams in Tencent have been using CLoudBase Framework X Flutter development mode, which has improved the r&d efficiency by 100%

5. Write at the end

5.1 Open Source Contribution

The CloudBase Framework project has been open source on Github. We welcome all developers to contribute to the CloudBase Framework project, so that the project can better help developers improve development efficiency

Github.com/TencentClou…

(Also welcome to give the project a Star, support us to do better ~)

5.2 Online Communication

Welcome to join our QQ group or wechat group to communicate.

QQ communication group of

Wechat communication group

Cloud Development (TCB) is a cloud native integrated development environment and tool platform provided by Tencent Cloud. It provides developers with highly available, automatic and flexible expansion of back-end cloud services, including computing, storage, hosting and other serverless capabilities, which can be used for cloud integrated development of various end applications (small programs, Public account, Web application, Flutter client, etc.) to help developers build and manage back-end services and cloud resources in a unified manner, avoiding tedious server construction, operation and maintenance during application development. Developers can focus on the implementation of business logic, with lower development threshold and higher efficiency.

The product documentation: cloud.tencent.com/product/tcb

Technical documentation: Cloudbase.net

Technical exchange plus Q group: 601134960

Latest news follow wechat official account [Tencent Yunyun Development]