Skip to content

Instance Functions

Overview

Instance functions operate directly on values and expressions within EL (Expression Language), enabling method-style chaining and manipulation. Unlike static functions that are called globally, instance functions are invoked on specific objects using dot notation. This approach provides object-oriented access to common operations like string manipulation, collection queries, and numeric transformations.

Argument-less members are also available without parentheses as properties${name.length} and ${name.length()} return the same value.

Important

Not all Dart instance methods are supported. Calling an unsupported function throws Exception: Function '<name>' not found. The functions listed below are the built-in instance methods; functions stored as Map values are also callable as methods on that map.

Numeric Functions

abs

Returns the absolute value of a number.

T abs();
<Text data="${temperature.abs()}"/>

ceil

Rounds a number up to the nearest integer.

int ceil();
<Text data="${price.ceil()}"/>

floor

Rounds a number down to the nearest integer.

int floor();
<Text data="${score.floor()}"/>

round

Rounds a number to the nearest integer.

int round();
<Text data="${average.round()}"/>

truncate

Truncates a number to an integer by removing the fractional part.

int truncate();
<Text data="${value.truncate()}"/>

toDouble

Converts a number to a double.

double toDouble();
<Text data="${count.toDouble()}"/>

toInt

Converts a number to an integer.

int toInt();
<Text data="${ratio.toInt()}"/>

toRadixString

Converts a number to a string representation in the specified radix (base).

String toRadixString(int radix);
<Text data="${number.toRadixString(16)}"/> <!-- Hexadecimal -->

isEven

Checks if a number is even.

bool isEven();
<if test="${index.isEven()}">
    <!-- true condition -->
</if>

isOdd

Checks if a number is odd.

bool isOdd();
<if test="${position.isOdd()}">
    <!-- true condition -->
</if>

isFinite

Checks if a number is finite.

bool isFinite();
<if test="${value.isFinite()}">
    <!-- true condition -->
</if>

isInfinite

Checks if a number is infinite.

bool isInfinite();
<if test="${result.isInfinite()}">
    <!-- true condition -->
</if>

isNaN

Checks if a number is Not-a-Number (NaN).

bool isNaN();
<if test="${calculation.isNaN()}">
    <!-- true condition -->
</if>

isNegative

Checks if a number is negative.

bool isNegative();
<if test="${balance.isNegative()}">
    <!-- true condition -->
</if>

compareTo

Compares this number to another, returning -1, 0, or 1.

int compareTo(T other);
<if test="${score.compareTo(passingScore) >= 0}">
    <!-- true condition -->
</if>

String Functions

length

Returns the length of a string.

int length();
<Text data="${username.length()}"/>

isEmpty

Checks if a string is empty.

bool isEmpty();
<if test="${message.isEmpty()}">
    <!-- true condition -->
</if>

isNotEmpty

Checks if a string is not empty.

bool isNotEmpty();
<if test="${email.isNotEmpty()}">
    <!-- true condition -->
</if>

toLowerCase

Converts a string to lowercase.

String toLowerCase();
<Text data="${title.toLowerCase()}"/>

toUpperCase

Converts a string to uppercase.

String toUpperCase();
<Text data="${(firstName + ' ' + lastName).toUpperCase()}"/>

trim

Removes leading and trailing whitespace.

String trim();
<Text data="${userInput.trim()}"/>

trimLeft

Removes leading whitespace.

String trimLeft();
<Text data="${text.trimLeft()}"/>

trimRight

Removes trailing whitespace.

String trimRight();
<Text data="${text.trimRight()}"/>

startsWith

Checks if a string starts with the specified substring.

bool startsWith(String other, [int index = 0]);
<if test="${fileName.startsWith('tmp_')}">
    <!-- true condition -->
</if>

endsWith

Checks if a string ends with the specified substring.

bool endsWith(String other);
<if test="${fileName.endsWith('.dart')}">
    <!-- true condition -->
</if>

contains

Checks if a string contains the specified substring.

bool contains(String element);
<if test="${description.contains('urgent')}">
    <!-- true condition -->
</if>

indexOf

Returns the index of the first occurrence of a substring.

int indexOf(String element, [int start = 0]);
<Text data="${text.indexOf('@')}"/>

lastIndexOf

Returns the index of the last occurrence of a substring.

int lastIndexOf(String element, [int start]);
<Text data="${path.lastIndexOf('/')}"/>

substring

Extracts a substring from start to end index.

String substring(int start, [int? end]);
<Text data="${fullName.substring(0, 10)}"/>

split

Splits a string into a list using the specified pattern.

List<String> split(Pattern pattern);
<Text data="${csv.split(',')}"/>

replaceAll

Replaces all occurrences of a pattern with a replacement string.

String replaceAll(Pattern from, String replace);
<Text data="${text.replaceAll(' ', '_')}"/>

replaceFirst

Replaces the first occurrence of a pattern with a replacement string.

String replaceFirst(Pattern from, String replace, [int startIndex = 0]);
<Text data="${message.replaceFirst('error', 'warning')}"/>

replaceRange

Replaces the substring from start to end with a replacement string.

String replaceRange(int start, int end, String replacement);
<Text data="${text.replaceRange(0, 5, 'Hello')}"/>

padLeft

Pads a string on the left to reach the specified width.

String padLeft(int width, [String padding = ' ']);
<Text data="${id.padLeft(8, '0')}"/>

padRight

Pads a string on the right to reach the specified width.

String padRight(int width, [String padding = ' ']);
<Text data="${label.padRight(20, '.')}"/>

toString

Converts a value to its string representation.

String toString();
<Text data="${userId.toString()}"/>

Collection Functions

length

Returns the number of elements in a collection.

int length();
<Text data="${items.length()}"/>

isEmpty

Checks if a collection is empty.

bool isEmpty();
<if test="${cart.isEmpty()}">
    <!-- true condition -->
</if>

isNotEmpty

Checks if a collection is not empty.

bool isNotEmpty();
<if test="${notifications.isNotEmpty()}">
    <!-- true condition -->
</if>

first

Returns the first element in a collection.

E first();
<Text data="${items.first()}"/>

last

Returns the last element in a collection.

E last();
<Text data="${items.last()}"/>

single

Returns the single element in a collection (throws if not exactly one element).

E single();
<Text data="${results.single()}"/>

elementAt

Returns the element at the specified index.

E elementAt(int index);
<Text data="${items.elementAt(2)}"/>

contains

Checks if a collection contains the specified element.

bool contains(E element);
<if test="${tags.contains('featured')}">
    <!-- true condition -->
</if>

indexOf

Returns the index of the first occurrence of an element.

int indexOf(E element, [int start = 0]);
<Text data="${items.indexOf('target')}"/>

lastIndexOf

Returns the index of the last occurrence of an element.

int lastIndexOf(E element, [int start]);
<Text data="${items.lastIndexOf('duplicate')}"/>

sublist

Returns a sublist from start to end index.

List<E> sublist(int start, [int? end]);
<Text data="${items.sublist(0, 5)}"/>

toList

Converts a collection to a list.

List<E> toList({bool growable = true});
<Text data="${items.toList()}"/>

toSet

Converts a collection to a set.

Set<E> toSet();
<Text data="${items.toSet()}"/>

shuffle

Randomly shuffles the elements in a list.

void shuffle([Random? random]);
<!-- expressions evaluate at inflation time; use <callback> to defer to the tap -->
<Button>
    <callback for="onPressed" action="items.shuffle()"/>
    <Text data="Shuffle"/>
</Button>

Map Functions

containsKey

Checks if a map contains the specified key.

bool containsKey(K key);
<if test="${user.containsKey('email')}">
    <!-- true condition -->
</if>

containsValue

Checks if a map contains the specified value.

bool containsValue(V value);
<if test="${settings.containsValue(true)}">
    <!-- true condition -->
</if>

keys

Returns an iterable of all keys in the map.

Iterable<K> keys();
<Text data="${config.keys()}"/>

values

Returns an iterable of all values in the map.

Iterable<V> values();
<Text data="${scores.values()}"/>

entries

Returns an iterable of all key-value pairs in the map.

Iterable<MapEntry<K, V>> entries();
<Text data="${userData.entries()}"/>

isEmpty

Checks if a map is empty.

bool isEmpty();
<if test="${cache.isEmpty()}">
    <!-- true condition -->
</if>

isNotEmpty

Checks if a map is not empty.

bool isNotEmpty();
<if test="${options.isNotEmpty()}">
    <!-- true condition -->
</if>

length

Returns the number of key-value pairs in the map.

int length();
<Text data="${userData.length()}"/>

Set Functions

difference

Returns a set containing elements in this set but not in the other set.

Set<E> difference(Set<Object> other);
<Text data="${setA.difference(setB)}"/>

intersection

Returns a set containing elements present in both sets.

Set<E> intersection(Set<Object> other);
<Text data="${setA.intersection(setB)}"/>

union

Returns a set containing all elements from both sets.

Set<E> union(Set<E> other);
<Text data="${setA.union(setB)}"/>

Object Functions

runtimeType

Returns the runtime type of an object.

Type runtimeType();
<Text data="${value.runtimeType()}"/>

toString

Returns a string representation of an object.

String toString();
<Text data="${object.toString()}"/>