params library

Firebase Functions parameter system.

Provides strongly-typed configuration that works at both deploy time and runtime. Parameters can be defined using factory functions and their values are read from environment variables.

Basic Usage

import 'package:firebase_functions/params.dart';

// Define parameters
final welcomeMessage = defineString(
  'WELCOME_MESSAGE',
  ParamOptions(defaultValue: 'Hello!'),
);

final minInstances = defineInt(
  'MIN_INSTANCES',
  ParamOptions(defaultValue: 0),
);

// Use at runtime
firebase.https.onRequest(
  name: 'greet',
  (request) async {
    return Response.ok(welcomeMessage.value());
  },
);

Secrets

For sensitive values, use secrets stored in Cloud Secret Manager:

final apiKey = defineSecret('API_KEY');

firebase.https.onRequest(
  name: 'secure',
  options: HttpsOptions(secrets: [apiKey]),
  (request) async {
    final key = apiKey.value();
    return Response.ok('Using API key');
  },
);

Built-in Parameters

Several parameters are built-in and always available:

Conditional Configuration

Use boolean parameters for conditional deployment configuration:

final isProduction = defineBoolean('IS_PRODUCTION');

firebase.https.onRequest(
  name: 'api',
  options: HttpsOptions(
    minInstances: isProduction.thenElse(2, 0),
  ),
  handler,
);

Classes

BooleanParam
A boolean parameter.
DoubleParam
A double/float parameter.
EnumListParam<T extends Enum>
An enum list parameter.
Equals<T extends Object>
Equality comparison expression.
Expression<T extends Object>
Abstract base class for all expressions in Firebase Functions.
GreaterThan
Greater than comparison expression (numbers only).
GreaterThanOrEqualTo
Greater than or equal comparison expression (numbers only).
If<T extends Object>
A conditional expression (ternary operator).
InternalExpression
Internal expression for Firebase-provided values.
IntParam
An integer parameter.
JsonSecretParam<T>
A JSON secret parameter that auto-parses the stored value.
LessThan
Less than comparison expression (numbers only).
LessThanOrEqualTo
Less than or equal comparison expression (numbers only).
ListParam
A string list parameter.
LiteralExpression<T extends Object>
A literal expression that wraps a constant value.
MultiSelectParamInput
Multi-select input from a list of options.
NotEquals<T extends Object>
Inequality comparison expression.
Param<T extends Object>
Abstract base class for all parameters.
ParamInput<T extends Object>
Sealed class hierarchy for parameter input types.
ParamOptions<T extends Object>
Configuration options for customizing parameter prompting behavior.
ResourceInput
Resource picker input (e.g., for selecting a Cloud Storage bucket).
SecretParam
A secret parameter stored in Cloud Secret Manager.
SelectOption<T extends Object>
An option in a select or multi-select input.
SelectParamInput<T extends Object>
Single-select input from a list of options.
StringParam
A string parameter.
TextParamInput<T extends Object>
Text input with optional validation.
WireParamSpec<T extends Object>
Wire representation of a parameter spec for the CLI.

Constants

bucketPicker → const ResourceInput
Resource input for selecting a Cloud Storage bucket.

Properties

databaseURL Param<String>
Built-in parameter that resolves to the Realtime Database URL.
final
declaredParams List<Object>
All declared parameters, used for manifest generation.
final
gcloudProject Param<String>
Built-in parameter that resolves to the GCloud project ID.
final
projectID Param<String>
Built-in parameter that resolves to the Cloud project ID.
final
storageBucket Param<String>
Built-in parameter that resolves to the Cloud Storage bucket.
final

Functions

clearParams() → void
Clears all registered parameters. For testing only.
defineBoolean(String name, [ParamOptions<bool>? options]) BooleanParam
Creates a boolean parameter.
defineDouble(String name, [ParamOptions<double>? options]) DoubleParam
Creates a double/float parameter.
defineEnumList<T extends Enum>(List<T> values, [ParamOptions<List<T>>? options]) EnumListParam<T>
Creates an enum list parameter from enum values.
defineFloat(String name, [ParamOptions<double>? options]) DoubleParam
Creates a float parameter.
defineInt(String name, [ParamOptions<int>? options]) IntParam
Creates an integer parameter.
defineJsonSecret<T>(String name) JsonSecretParam<T>
Creates a JSON secret parameter that auto-parses the value.
defineList(String name, [ParamOptions<List<String>>? options]) ListParam
Creates a string list parameter.
defineSecret(String name) SecretParam
Creates a secret parameter that reads from Cloud Secret Manager.
defineString(String name, [ParamOptions<String>? options]) StringParam
Creates a string parameter.
onInit(FutureOr<void> callback()) → void
Registers a callback to run once before any function executes.