Expression<T> class sealed

A value of a style property or an argument of another expression: either a constant (Expression.literal) or a style expression that the map evaluates.

T is the Dart type the expression evaluates to, such as num, String, bool, Color, Offset, a List or a spec enum like LineCap.

CircleStyleLayer(
  id: 'quakes',
  sourceId: 'quakes',
  filter: .all([
    .greaterThan(.get('mag').asNumber(), .literal(5)),
    .has('place'),
  ]),
  radius: .interpolate(.exponential(2), .zoom(), {
    5: .literal(2),
    10: .literal(8),
  }),
);

Dot shorthands don't work as operands of an operator. Start with Expression. there: Expression.get('mag').asNumber() > .literal(5).

Spec names are kept, except for those that clash with Dart keywords or members: case is select, in is contains, let and var are withVariable, ! is not(), == and != are equal and notEqual, typeof is type, string, number and boolean are asString, asNumber and asBoolean, and to-string and the like are convertToString and the like.

Available extensions
Annotations

Constructors

Expression.literal(T value)
The constant value.
const
factory
Expression.raw(List<Object?> json)
The expression json in the JSON form of the style spec. The fallback for anything not covered by this class.
const
factory

Properties

hashCode → int
The hash code for this object.
no setteroverride
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The absolute value (spec: abs).
acos() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The arccosine (spec: acos).
asArray<E>({int? length}) → Expression<List<E>>
Asserts that this value is an array of E, optionally of length items (spec: array). Only num, String and bool can be asserted as item types; any other E asserts an array of any items, which can't be combined with a length.
asBoolean([List<Expression<Object?>> fallbacks = const []]) → Expression<bool>
Asserts that this value is a boolean. If it isn't, the fallbacks are tried in order (spec: boolean).
asin() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The arcsine (spec: asin).
asNumber([List<Expression<Object?>> fallbacks = const []]) → Expression<num>
Asserts that this value is a number. If it isn't, the fallbacks are tried in order (spec: number).
asObject([List<Expression<Object?>> fallbacks = const []]) → Expression<Map<String, Object?>>
Asserts that this value is an object. If it isn't, the fallbacks are tried in order (spec: object).
asString([List<Expression<Object?>> fallbacks = const []]) → Expression<String>
Asserts that this value is a string. If it isn't, the fallbacks are tried in order (spec: string).
at(Expression<num> index) → Expression<E>

Available on Expression<List<E>>, provided by the ListExpression extension

The item at index (spec: at).
atan() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The arctangent (spec: atan).
cast<R>() → Expression<R>
Asserts nothing and only changes the static type to R. Use asString, asNumber or asBoolean for an assertion that the map checks. A Literal whose value is not an R becomes a RawValue of its JSON.
ceil() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The smallest integer not below this (spec: ceil).
contains(Expression<String> substring) → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether this contains substring (spec: in).
contains(Expression<E> item) → Expression<bool>

Available on Expression<List<E>>, provided by the ListExpression extension

Whether this contains item (spec: in).
convertToBoolean() → Expression<bool>
Converts this value to a boolean (spec: to-boolean).
convertToColor([List<Expression<Object?>> fallbacks = const []]) → Expression<Color>
Converts this value to a color. If that fails, the fallbacks are tried in order (spec: to-color).
convertToNumber([List<Expression<Object?>> fallbacks = const []]) → Expression<num>
Converts this value to a number. If that fails, the fallbacks are tried in order (spec: to-number).
convertToString() → Expression<String>
Converts this value to a string (spec: to-string).
cos() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The cosine (spec: cos).
downcase() → Expression<String>

Available on Expression<String>, provided by the StringExpression extension

This in lowercase (spec: downcase).
floor() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The largest integer not above this (spec: floor).
indexOf(Expression<E> item, {Expression<num>? from}) → Expression<num>

Available on Expression<List<E>>, provided by the ListExpression extension

The position of the first item at or after from, or -1 (spec: index-of).
indexOf(Expression<String> substring, {Expression<num>? from}) → Expression<num>

Available on Expression<String>, provided by the StringExpression extension

The position of the first substring at or after from, or -1 (spec: index-of).
isSupportedScript() → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether the map can render this string's script (spec: is-supported-script).
join(Expression<String> separator) → Expression<String>

Available on Expression<List<E>>, provided by the ListExpression extension

The items joined by separator (spec: join).
length() → Expression<num>

Available on Expression<String>, provided by the StringExpression extension

The length in UTF-16 code units (spec: length).
length() → Expression<num>

Available on Expression<List<E>>, provided by the ListExpression extension

The number of items (spec: length).
ln() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The natural logarithm (spec: ln).
log10() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The base-ten logarithm (spec: log10).
log2() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The base-two logarithm (spec: log2).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
not() → Expression<bool>

Available on Expression<bool>, provided by the BoolExpression extension

The opposite of this (spec: !).
numberFormat({Expression<String>? locale, Expression<String>? currency, Expression<num>? minFractionDigits, Expression<num>? maxFractionDigits}) → Expression<String>

Available on Expression<num>, provided by the NumExpression extension

This number as a string in a locale-dependent format (spec: number-format).
pow(Expression<num> exponent) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

This to the power of exponent (spec: ^).
resolvedLocale() → Expression<String>

Available on Expression<Collator>, provided by the CollatorExpression extension

The IETF language tag of the locale of this collator (spec: resolved-locale).
round() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

Rounded to the nearest integer, halves away from zero (spec: round).
sin() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The sine (spec: sin).
slice(Expression<num> start, [Expression<num>? end]) → Expression<List<E>>

Available on Expression<List<E>>, provided by the ListExpression extension

The items from start, up to end if given (spec: slice).
slice(Expression<num> start, [Expression<num>? end]) → Expression<String>

Available on Expression<String>, provided by the StringExpression extension

The part of this from start, up to end if given (spec: slice).
split(Expression<String> separator) → Expression<List<String>>

Available on Expression<String>, provided by the StringExpression extension

The substrings between the occurrences of separator (spec: split).
sqrt() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The square root (spec: sqrt).
tan() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The tangent (spec: tan).
toJson() → Object?
The expression in the JSON form of the style spec.
toRgba() → Expression<List<num>>

Available on Expression<Color>, provided by the ColorExpression extension

The red, green, blue and alpha components of this color (spec: to-rgba).
toString() → String
A string representation of this object.
override
type() → Expression<String>
The type of this value as a string (spec: typeof).
upcase() → Expression<String>

Available on Expression<String>, provided by the StringExpression extension

This in uppercase (spec: upcase).

Operators

operator %(Expression<num> other) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The remainder of this divided by other (spec: %).
operator *(Expression<num> other) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The product of this and other (spec: *).
operator +(Expression<num> other) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

The sum of this and other (spec: +).
operator +(Expression<String> other) → Expression<String>

Available on Expression<String>, provided by the StringExpression extension

This and other joined (spec: concat).
operator -(Expression<num> other) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

This minus other (spec: -).
operator /(Expression<num> other) → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

This divided by other (spec: /).
operator <(Expression<num> other) → Expression<bool>

Available on Expression<num>, provided by the NumExpression extension

Whether this is less than other (spec: <).
operator <(Expression<String> other) → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether this sorts before other (spec: <).
operator <=(Expression<num> other) → Expression<bool>

Available on Expression<num>, provided by the NumExpression extension

Whether this is less than or equal to other (spec: <=).
operator <=(Expression<String> other) → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether this sorts before or equal to other (spec: <=).
operator ==(Object other) → bool
The equality operator.
override
operator >(Expression<num> other) → Expression<bool>

Available on Expression<num>, provided by the NumExpression extension

Whether this is greater than other (spec: >).
operator >(Expression<String> other) → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether this sorts after other (spec: >).
operator >=(Expression<num> other) → Expression<bool>

Available on Expression<num>, provided by the NumExpression extension

Whether this is greater than or equal to other (spec: >=).
operator >=(Expression<String> other) → Expression<bool>

Available on Expression<String>, provided by the StringExpression extension

Whether this sorts after or equal to other (spec: >=).
operator unary-() → Expression<num>

Available on Expression<num>, provided by the NumExpression extension

This negated (spec: -).

Static Methods

accumulated() → Expression<Object?>
The value of a cluster property accumulated so far (spec: accumulated).
all(List<Expression<bool>> values) → Expression<bool>
Whether all of values are true (spec: all).
any(List<Expression<bool>> values) → Expression<bool>
Whether any of values is true (spec: any).
coalesce<R>(List<Expression<R>> values) → Expression<R>
The first of values that isn't null (spec: coalesce).
collator({Expression<bool>? caseSensitive, Expression<bool>? diacriticSensitive, Expression<String>? locale}) → Expression<Collator>
A collator for locale-dependent comparisons (spec: collator).
concat(List<Expression<Object?>> values) → Expression<String>
The values joined to one string (spec: concat). + joins two strings.
distance(Map<String, Object?> geometry) → Expression<num>
The shortest distance in meters from the feature to the GeoJSON geometry (spec: distance).
e() → Expression<num>
The mathematical constant e (spec: e).
elevation() → Expression<num>
The elevation in meters at a point (spec: elevation).
equal(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a equals b (spec: ==).
featureState(String name) → Expression<Object?>
The property name of the feature's state (spec: feature-state).
format(List<FormatSection> sections) → Expression<String>
A formatted string of mixed fonts and images, for a text field (spec: format).
geometryType() → Expression<String>
The geometry type of the feature (spec: geometry-type).
get(String name, {Expression<Map<String, Object?>>? object}) → Expression<Object?>
The property name of the feature, or of object if given (spec: get).
globalState(String name) → Expression<Object?>
The property name from the global state (spec: global-state).
greaterThan(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a is greater than b (spec: >).
greaterThanOrEqual(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a is greater than or equal to b (spec: >=).
has(String name, {Expression<Map<String, Object?>>? object}) → Expression<bool>
Whether the feature, or object if given, has the property name (spec: has).
heatmapDensity() → Expression<num>
The density at a point of a heatmap, for its color (spec: heatmap-density).
id() → Expression<Object?>
The id of the feature (spec: id).
image(Expression<String> name) → Expression<String>
The image name of the style, for an icon, pattern or formatted text (spec: image).
interpolate<R>(Interpolation interpolation, Expression<num> input, Map<num, Expression<R>> stops) → Expression<R>
Interpolates between the outputs of the stops at input (spec: interpolate). The stops are sorted on serialization.
interpolateHcl(Interpolation interpolation, Expression<num> input, Map<num, Expression<Color>> stops) → Expression<Color>
Like interpolate, for colors in the Hue-Chroma-Luminance color space (spec: interpolate-hcl).
interpolateLab(Interpolation interpolation, Expression<num> input, Map<num, Expression<Color>> stops) → Expression<Color>
Like interpolate, for colors in the CIELAB color space (spec: interpolate-lab).
lessThan(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a is less than b (spec: <).
lessThanOrEqual(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a is less than or equal to b (spec: <=).
lineProgress() → Expression<num>
The progress along a line from 0 to 1, for its gradient. Needs a GeoJSON source with line metrics (spec: line-progress).
ln2() → Expression<num>
The mathematical constant ln(2) (spec: ln2).
match<R>(Expression<Object?> input, Map<Object, Expression<R>> cases, {required Expression<R> fallback}) → Expression<R>
The output whose label equals input, or else fallback. A label is a string, a number or a list of them (spec: match).
max(List<Expression<num>> values) → Expression<num>
The largest of values (spec: max).
min(List<Expression<num>> values) → Expression<num>
The smallest of values (spec: min).
notEqual(Expression<Object?> a, Expression<Object?> b, {Expression<Collator>? collator}) → Expression<bool>
Whether a differs from b (spec: !=).
pi() → Expression<num>
The mathematical constant pi (spec: pi).
product(List<Expression<num>> values) → Expression<num>
The product of values (spec: *). * multiplies two.
properties() → Expression<Map<String, Object?>>
The properties of the feature (spec: properties).
rgb(Expression<num> red, Expression<num> green, Expression<num> blue) → Expression<Color>
A color of the components red, green and blue from 0 to 255 (spec: rgb).
rgba(Expression<num> red, Expression<num> green, Expression<num> blue, Expression<num> alpha) → Expression<Color>
A color of the components red, green and blue from 0 to 255 and alpha from 0 to 1 (spec: rgba).
select<R>(List<(Expression<bool>, Expression<R>)> branches, {required Expression<R> fallback}) → Expression<R>
The output of the first branch whose test is true, or else fallback (spec: case).
semiliteral<E>(List<Expression<E>> items) → Expression<List<E>>
An array of the items, which unlike a Expression.literal may be expressions (spec: semiliteral).
step<R>(Expression<num> input, Expression<R> output0, Map<num, Expression<R>> stops) → Expression<R>
The output of the last stop at or below input, or output0 below the first stop (spec: step). The stops are sorted on serialization.
sum(List<Expression<num>> values) → Expression<num>
The sum of values (spec: +). + adds two.
within(Map<String, Object?> geometry) → Expression<bool>
Whether the feature lies inside the GeoJSON geometry (spec: within).
withVariable<V, R>(String name, Expression<V> value, Expression<R> body(Variable<V> variable)) → Expression<R>
Binds value to the variable name for the expression that body returns (spec: let and var).
zoom() → Expression<num>
The zoom level of the map (spec: zoom).