How to Get Started with Celest: Your Flutter Cloud Platform

Jul 27, 2024 | Programming

Welcome to the exciting world of Celest! If you’re a Flutter and Dart developer looking to streamline your backend infrastructure, you’re in the right place. This article will guide you step-by-step in setting up Celest in your Flutter application.

Prerequisites

Before diving into the intricate steps of creating your Celest project, make sure you have the following prerequisites in place:

  • Install Flutter
  • Create a new Flutter project or choose an existing one
  • Download and install the Celest CLI

Creating a Celest Project

You’re now ready to start building your backend—all in Dart! Here’s how to create your Celest project:

shell
$ flutter create flutter_app
$ cd flutter_app
$ celest start

Think of this step as laying the foundation of a house before decorating the interiors. By running the commands above, you are constructing the framework for your cloud functions.

Once the command executes, Celest will spin up a local environment and start watching for changes made to your backend, generating a Dart client for you to test modifications. You’ll notice a new folder named celest appearing in your project with predefined structures for using Celest Functions.

Understanding Celest Functions

Next, let’s delve into how to create your serverless cloud functions. Navigate to the flutter_app/celest/functions folder and create a new file named api_name.dart. Here’s where the magic happens:

dart
@cloud
Future sayHello(String name) async {
    return 'Hello, $name';
}
@cloud
Future sayGoodbye(String name) async {
    return 'Goodbye, $name';
}

Imagine these functions as friendly servants ready to greet or bid farewell to your app users. Once defined, you can connect your Flutter app to these cloud functions to enhance its functionality!

Integrating Celest Client

Now that your API is set up, let’s connect it to your Flutter app. Replace the contents of your main.dart file with the following snippet:

dart
import 'package:flutter/material.dart'; 
import 'package:celest_backend/client.dart';

void main() {
    celest.init(environment: CelestEnvironment.local);
    runApp(const MyApp());
}

class MyApp extends StatelessWidget {
    const MyApp(super.key);

    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: Scaffold(
                appBar: AppBar(
                    title: const Text('Homepage'),
                ),
                body: Center(
                    child: FutureBuilder(
                        future: celest.functions.greeting.sayHello('Celest'),
                        builder: (_, snapshot) {
                            switch (snapshot) {
                                AsyncSnapshot data => Text(data),
                                AsyncSnapshot error => Text('$error.runtimeType: $error'),
                                _ => const CircularProgressIndicator(),
                            };
                        },
                    ),
                ),
            ),
        );
    }
}

Think of this code integration as giving your app a voice; it allows your app to communicate dynamically with backend functions just like a customer interacting with service agents!

Examples and Additional Resources

To see Celest in action, check out our examples:

Troubleshooting

If you run into issues while setting up your Celest project, consider the following troubleshooting tips:

  • Ensure that Flutter is correctly installed and available in your system’s path.
  • Double-check that the Celest CLI is properly set up and functioning.
  • If you encounter issues with API connectivity, verify your code for typos and logic errors.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

Congratulations on setting up your Celest project and integrating it with your Flutter app! At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox