Building Backend with Flutter using Celest

Image designed by Freepik

Introduction

Flutter is an open-source software development kit created by Google as a one-stop solution for building web, mobile, and desktop applications. However, when it comes to back-end development, Flutter developers often have to use multiple tools and languages which can increase project complexity and disrupt the development process. Celest aims to provide a solution for this problem by offering a backend-as-a-service specifically designed for Flutter developers.

Celest allows developers to build their backend entirely in Dart, eliminating the need for additional tooling or context switching to different programming languages. This service not only simplifies the development process but also allows seamless sharing of logic and code between Flutter applications and their backends. This article aims to provide an overview of the steps involved in order to build a backend for your Flutter application using Celest and highlight its advantages.

Installation and Setup

1. Download the Celest CLI from the official website and follow the installation instructions. 

2. Create your Flutter project.

3. Inside the Flutter project direct, run celest start from the terminal. This will create a new folder called “celest” in your project directory that contains the backend logic for the application.

Below is a table detailing the CLI commands for Celest:

Command Description
celest start Creates a new Celest project
celest deploy Deploys the Celest project to the cloud
celest upgrade Upgrades Celest CLI to the latest version
celest uninstall Uninstalls Celest
celest --help Show all available commands for Celest
celest --version Shows the current version of Celest CLI

Creating a Function (API)

1. Navigate to the functions folder inside the newly created celest folder.

2. Create a new dart file.

3. Code away your API functions using Dart. Below is a simple example retrieved from the official website that features two functions:


Future<String> sayHello(String name) async {
    return 'Hello, $name';
}

Future<String> sayGoodbye(String name) async {
    return 'Goodbye, $name';
}

    

Connect the Flutter application to The Cloud Functions

1. Import celest in the main.dart file:


import 'package:celest_backend/client.dart';

    

2. Initiate celest by including celest.init() in the main function of the main. dart file.

If you’ve followed the steps above, you should be good to go. You can now utilize your back-end functions defined in the celest directory directly in the flutter by calling them using:


celest.functions.<api_name>.<function_name>

    

Additional Features

Working with custom data types: To work with user-defined data structures, you must place them in the celest/lib/models file for them to work with the backend functions.

Celest Auth: Currently, only email-based authentication via OTP is implemented. This can be used by including the following code in your application:


import 'package:celest/celest_dart';

const auth = Auth(
    providers: [
        AuthProvider.email(),
    ],
);

    

Authorizing your functions: By default, Celest only allows the admin to access functions. However, this can be changed by using one of the following annotations: @public (grants access to anyone on the internet) and @authenticated (grants access to authenticated users)

Writing Tests: Within the Celest/Test folder, you can create a new Dart file and define unit tests. In order to run the tests, run the following command in the terminal: dart test

Third-Party Packages: Celest supports all third-party packages that are compatible with Dart to be included in the backend functions.

Advantages of Using Celest

Integration with Flutter: Since Celest utilizes Dart, it allows developers to share logic and code between the two resulting in a more efficient development process and eliminating the need for context switching.

Hot Reloading: Celest allows developers to build cloud features locally and test them on the fly by using hot reload, which significantly improves the iteration speed.

Cloud Widgets: Celest offers a set of pre-built cloud widgets that include common backend functionalities such as authentication which can streamline the development process. The list of functionalities will continue to grow as the developers at Celest are actively updating their framework.

Separation Layer: By separating the business logic and the UI layer, Celest enables developers to add features to their backend without requiring a new version deployment to the app store. 

Dart Package Integration: Developers can take advantage of the large number of Dart packages already available and integrate them into their backend functions.

Conclusion

Celest offers a backend-as-a-service solution designed specifically for Flutter developers. By allowing the entire backend to be built using Dart, Celest streamlines development and enables seamless integration between the frontend and backend components. Key benefits include the ability to share logic and code, hot reloading for efficient iteration, pre-built cloud widgets with common functionality, and separation of business logic from the UI layer. As Celest continues to grow towards its goal of “turning every Flutter developer into a full-stack developer”, it can become an invaluable tool for Flutter developers.

References

https://celest.dev/docs/overview

https://www.ycombinator.com/companies/celest

Previous
Previous

Top 20 GenAI Products for Education

Next
Next

How to Store & Protect Personal Context in ChatGPT