Get started with the experimental Dart SDK

Experimental Dart support in Cloud Functions for Firebase lets you build full-stack apps with Flutter and Dart. Communicate with other Firebase services with the new Firebase Admin Dart SDK.

To get started with Dart functions, work through the setup tasks in this guide and then continue exploring Dart HTTP and callable functions.

Prerequisites

Check that you have a version of the Firebase CLI that supports Dart in Cloud Functions for Firebase with the --version flag:

 `firebase --version`

Enable the experiment in the Firebase CLI

firebase experiments:enable dartfunctions

Initialize your project

  1. Run: bash firebase init functions
  2. Select Dart as your language.
  3. When asked "Do you want to install dependencies now?", answer "Yes".

View your function code

View the code that was generated in functions/bin/server.dart (or your entry point). This code demonstrates a simple HTTP function.

Note that the sample code sets the maximum number of instances for the helloWorld function to 10 with the HttpsOptions constructor. You can learn more about runtime options in Set runtime options.

Test locally

firebase emulators:start

Once the Local Emulator Suite boots up, you'll see a log line like functions http function initialized (http://127.0.0.1:5001/<url>). Load that URL in your browser to call your locally emulated Dart function.

If you edit your Dart code, the Firebase Local Emulator Suite will detect the change and automatically reload your function.

Deploy

firebase deploy --only functions

The deployment process for Dart is different from Node.js or Python functions. Instead of uploading your source code to be built in Cloud Build, the Firebase CLI runs a Dart compile step on your development machine and uploads the generated binary directly to Cloud Run functions.

When the deployment is complete, you'll see a log line like Function URL (hello-world(us-central1)): https://hello-world-<random-hash>.<region>.run.app

Load that URL in your browser to call your newly deployed Dart function.

Next steps

Limitations

  • The onCall trigger can be deployed, but cannot be called from client SDKs with methods such as httpsCallable, which identify functions by name. You can instead use methods such as httpsCallableFromURL and pass the full Cloud Run URL of your function.
  • Other triggers, such as Firestore triggers, can be run in the local emulator suite, but cannot be deployed.
  • The Firebase console does not display Dart functions during the experimental release. You can view Dart functions in the Cloud Run functions page of the Cloud console instead.

If you discover issues while working with Dart functions, you're encouraged to send the team a report to help us improve and expand the experimental Dart SDK.