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.

> [!CAUTION]
> **Caution:** This feature is **experimental** and may change without notice.

## Prerequisites

- [Dart SDK 3.9 or higher](https://dart.dev/get-dart)
- [Firebase CLI](https://firebase.google.com/docs/cli.md.txt) (version 15.15.0 or higher)

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

```bash
 `firebase --version`
```

> [!NOTE]
> **Note:** You can emulate functions locally with any Firebase project, but to deploy functions, your project must be on the [Blaze pricing plan](https://firebase.google.com/pricing.md.txt). See [Cloud Functions pricing](https://firebase.google.com/docs/functions/faq-and-troubleshooting.md.txt#functions-pricing).

## Enable the experiment in the Firebase CLI

```bash
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](https://firebase.google.com/docs/functions/manage-functions#set-runtime-options).

## Test locally

```bash
firebase emulators:start
```

Once the [Local Emulator Suite](https://firebase.google.com/docs/emulator-suite.md.txt) 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.

> [!NOTE]
> **Note:** Only the HTTP trigger ( `onRequest` ) and HTTP callable (`onCall`) triggers are supported for Dart in this experimental release. Other triggers can be run in the emulator, but cannot be deployed. See [Limitations](https://firebase.google.com/docs/functions/start-dart.md.txt#limitations) for more information.

## Deploy

```bash
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

- Set [configuration options](https://pub.dev/packages/firebase_functions#using-parameters-in-options-deploy-time) like minimum instances.
- Learn more about [HTTP functions](https://firebase.google.com/docs/functions/http-events.md.txt) and [callable functions](https://firebase.google.com/docs/functions/callable.md.txt).
- Follow the Dart Functions codelab [Dart Functions codelab](https://codelabs.developers.google.com/deploy-dart-on-firebase-functions)
- Use the experimental [Dart Admin SDK](https://firebase.google.com/docs/admin/setup.md.txt) to interact with other Firebase services, like Cloud Firestore, from your function
- In addition to `onRequest` HTTP functions, you can try an [`onCall` sample](https://github.com/firebase/functions-samples/tree/main/Dart/quickstarts/callable-functions) or [`onCall` with streaming](https://github.com/firebase/functions-samples/tree/main/Dart/quickstarts/callable-functions-streaming) sample to [call functions directly from your app](https://firebase.google.com/docs/functions/callable.md.txt) (noting the special limitation regarding the calling method).

## Limitations

- The `onCall` trigger can be deployed, but cannot be called from client SDKs with methods such as [httpsCallable](https://firebase.google.com/docs/reference/js/functions.md.txt#httpscallable_1dd297c), which identify functions by name. You can instead use methods such as [httpsCallableFromURL](https://firebase.google.com/docs/reference/js/functions.md.txt#httpscallablefromurl_7af6987) 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](https://console.cloud.google.com/) instead.

If you discover issues while working with Dart functions, you're encouraged to
[send the team a report](https://github.com/firebase/firebase-functions-dart/issues/new/choose)
to help us improve and expand the experimental Dart SDK.