when<R extends Object> method

If<R> when<R extends Object>({
  1. required Expression<R> then,
  2. required Expression<R> otherwise,
})

Creates a conditional expression (ternary operator).

This method can only be called on boolean expressions (like BooleanParam or comparison results).

Example:

final isProduction = defineBoolean('IS_PRODUCTION');
final region = isProduction.when(
  then: LiteralExpression(['us-central1', 'europe-west1']),
  otherwise: LiteralExpression(['us-central1']),
);

Implementation

If<R> when<R extends Object>({
  required Expression<R> then,
  required Expression<R> otherwise,
}) {
  if (this is! Expression<bool>) {
    throw ArgumentError('when() can only be called on Expression<bool>');
  }
  return If(this as Expression<bool>, then: then, otherwise: otherwise);
}