Skip to content

Static Functions

Overview

These functions are universally accessible within every EL (Expression Language) expression, providing powerful tools for manipulation and evaluation. They are designed to accept other expressions as arguments, enabling dynamic and flexible computation. This allows for the creation of complex expressions by combining multiple functions and expressions, enhancing the overall functionality and usability of EL in various contexts.

Functions

abs

Absolute value.

Signature
num abs(dynamic value);
XML Usage
<Text data="${abs(-42)}"/>

ceil

Round up to nearest integer.

Signature
int ceil(dynamic value);
XML Usage
<Text data="${ceil(3.2)}"/>

contains

Check if a value contains a search value.

Signature
bool contains(dynamic value, dynamic searchValue);
XML Usage
<if test="${contains('Hello, World!', 'World')}">
    <!-- true condition -->
    <else>
        <!-- optional false condition -->
    </else>
</if>

containsKey

Check if a map contains a key.

Signature
bool containsKey(Map? map, dynamic searchKey);
XML Usage
<if test="${containsKey(myMap, 'userId')}">
    <!-- true condition -->
</if>

containsValue

Check if a map contains a value.

Signature
bool containsValue(Map? map, dynamic searchValue);
XML Usage
<if test="${containsValue(myMap, 'admin')}">
    <!-- true condition -->
</if>

diffDateTime

Calculate duration between two dates.

Signature
Duration diffDateTime(DateTime left, DateTime right);
XML Usage
<Text data="${diffDateTime(now(), startDate)}"/>

endsWith

Check if a string ends with a value.

Signature
bool endsWith(String value, String searchValue);
XML Usage
<if test="${endsWith(fileName, '.dart')}">
    <!-- true condition -->
</if>

eval

Evaluate an expression string.

Signature
dynamic eval(String? value);
XML Usage
<Text data="${eval('2 + 2')}"/>

first

Get first element of a collection.

Signature
dynamic first(dynamic value);
XML Usage
<Text data="${first(myList)}"/>

floor

Round down to nearest integer.

Signature
int floor(dynamic value);
XML Usage
<Text data="${floor(3.7)}"/>

formatDateTime

Format a DateTime with a pattern.

Signature
String formatDateTime(String format, DateTime dateTime);
XML Usage
<Text data="${formatDateTime('yyyy-MM-dd', now())}"/>

formatDuration

Format a Duration with specified precision.

Signature
String? formatDuration(Duration? value, [String precision = "s", DurationFormat? format = defaultDurationFormat]);
XML Usage
<Text data="${formatDuration(myDuration, 'ms')}"/>

isBlank

Check if a value is blank (null, empty, or whitespace).

Signature
bool isBlank(dynamic value);
XML Usage
<if test="${isBlank(userName)}">
    <!-- true condition -->
</if>

isEmpty

Check if a value is empty.

Signature
bool isEmpty(dynamic value);
XML Usage
<if test="${isEmpty(myList)}">
    <!-- true condition -->
    <else>
        <!-- optional false condition -->
    </else>
</if>

isFalseOrNull

Check if a value is false or null.

Signature
bool isFalseOrNull(dynamic value);
XML Usage
<if test="${isFalseOrNull(isEnabled)}">
    <!-- true condition -->
</if>

isNotBlank

Check if a value is not blank.

Signature
bool isNotBlank(dynamic value);
XML Usage
<if test="${isNotBlank(userName)}">
    <!-- true condition -->
</if>

isNotEmpty

Check if a value is not empty.

Signature
bool isNotEmpty(dynamic value);
XML Usage
<if test="${isNotEmpty(myList)}">
    <!-- true condition -->
</if>

isNotNull

Check if a value is not null.

Signature
bool isNotNull(dynamic value);
XML Usage
<if test="${isNotNull(userId)}">
    <!-- true condition -->
</if>

isNull

Check if a value is null.

Signature
bool isNull(dynamic value);
XML Usage
<if test="${isNull(userId)}">
    <!-- true condition -->
</if>

isTrueOrNull

Check if a value is true or null.

Signature
bool isTrueOrNull(dynamic value);
XML Usage
<if test="${isTrueOrNull(isEnabled)}">
    <!-- true condition -->
</if>

last

Get last element of a collection.

Signature
dynamic last(dynamic value);
XML Usage
<Text data="${last(myList)}"/>

length

Get length of a collection or string.

Signature
int length(dynamic value);
XML Usage
<Text data="${length('Hello')}"/>

logDebug

Log a debug message.

Signature
void logDebug(dynamic message);
XML Usage
<Button onPressed="${logDebug('Button clicked')}"/>

matches

Check if a string matches a regular expression.

Signature
bool matches(String value, String regExp);
XML Usage
<if test="${matches(email, '^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$')}">
    <!-- true condition -->
</if>

now

Get current DateTime.

Signature
DateTime now();
XML Usage
<Text data="${now()}"/>

nowInUtc

Get current DateTime in UTC.

Signature
DateTime nowInUtc();
XML Usage
<Text data="${nowInUtc()}"/>

randomDouble

Generate a random double between 0.0 and 1.0.

Signature
double randomDouble();
XML Usage
<Text data="${randomDouble()}"/>

randomInt

Generate a random integer.

Signature
int randomInt(int max);
XML Usage
<Text data="${randomInt(100)}"/>

replaceAll

Replace all occurrences in a string.

Signature
String replaceAll(String value, String regex, String replacement);
XML Usage
<Text data="${replaceAll('I enjoy programming', 'enjoy', 'love')}"/>

replaceFirst

Replace first occurrence in a string.

Signature
String replaceFirst(String value, String regex, String replacement, [int startIndex = 0]);
XML Usage
<Text data="${replaceFirst('test test', 'test', 'demo')}"/>

round

Round to nearest integer.

Signature
int round(dynamic value);
XML Usage
<Text data="${round(3.7)}"/>

startsWith

Check if a string starts with a value.

Signature
bool startsWith(String value, String searchValue);
XML Usage
<if test="${startsWith('Dart is fun', 'Dart')}">
    <!-- true condition -->
    <else>
        <!-- optional false condition -->
    </else>
</if>

substring

Extract a substring.

Signature
String substring(String value, int start, [int end = -1]);
XML Usage
<Text data="${substring('Hello World', 0, 5)}"/>

toBool

Convert to boolean.

Signature
bool? toBool(dynamic value);
XML Usage
<Text data="${toBool('true')}"/>

toColor

Convert to Color.

Signature
Color? toColor(dynamic value);
XML Usage
<Container color="${toColor('#FF5733')}"/>

toDateTime

Convert to DateTime.

Signature
DateTime? toDateTime(dynamic value);
XML Usage
<Text data="${toDateTime('2024-01-01')}"/>

toDays

Convert to days.

Signature
int? toDays(dynamic value);
XML Usage
<Text data="${toDays(myDuration)}"/>

toDouble

Convert to double.

Signature
double? toDouble(dynamic value);
XML Usage
<Text data="${toDouble('3.14')}"/>

toDuration

Convert to Duration.

Signature
Duration? toDuration(dynamic value, [String? intUnit]);
XML Usage
<Text data="${toDuration(3600, 's')}"/>

toHours

Convert to hours.

Signature
int? toHours(dynamic value);
XML Usage
<Text data="${toHours(myDuration)}"/>

toInt

Convert to integer.

Signature
int? toInt(dynamic value);
XML Usage
<Text data="${toInt('123')}"/>

toMillis

Convert to milliseconds.

Signature
int? toMillis(dynamic value);
XML Usage
<Text data="${toMillis(myDuration)}"/>

toMinutes

Convert to minutes.

Signature
int? toMinutes(dynamic value);
XML Usage
<Text data="${toMinutes(myDuration)}"/>

toSeconds

Convert to seconds.

Signature
int? toSeconds(dynamic value);
XML Usage
<Text data="${toSeconds(myDuration)}"/>

toString

Convert to string.

Signature
String? toString(dynamic value);
XML Usage
<Text data="${toString(42)}"/>

tryToBool

Try to convert to boolean, returns null on failure.

Signature
bool tryToBool(dynamic value);
XML Usage
<Text data="${tryToBool(userInput)}"/>

tryToColor

Try to convert to Color, returns null on failure.

Signature
Color? tryToColor(dynamic value);
XML Usage
<Container color="${tryToColor(userColor)}"/>

tryToDateTime

Try to convert to DateTime, returns null on failure.

Signature
DateTime? tryToDateTime(dynamic value);
XML Usage
<Text data="${tryToDateTime(userInput)}"/>

tryToDays

Try to convert to days, returns null on failure.

Signature
int? tryToDays(dynamic value);
XML Usage
<Text data="${tryToDays(userInput)}"/>

tryToDouble

Try to convert to double, returns null on failure.

Signature
double? tryToDouble(dynamic value);
XML Usage
<Text data="${tryToDouble(userInput)}"/>

tryToDuration

Try to convert to Duration, returns null on failure.

Signature
Duration? tryToDuration(dynamic value, [String? intUnit]);
XML Usage
<Text data="${tryToDuration(userInput, 's')}"/>

tryToHours

Try to convert to hours, returns null on failure.

Signature
int? tryToHours(dynamic value);
XML Usage
<Text data="${tryToHours(userInput)}"/>

tryToInt

Try to convert to integer, returns null on failure.

Signature
int? tryToInt(dynamic value);
XML Usage
<Text data="${tryToInt(userInput)}"/>

tryToMillis

Try to convert to milliseconds, returns null on failure.

Signature
int? tryToMillis(dynamic value);
XML Usage
<Text data="${tryToMillis(userInput)}"/>

tryToMinutes

Try to convert to minutes, returns null on failure.

Signature
int? tryToMinutes(dynamic value);
XML Usage
<Text data="${tryToMinutes(userInput)}"/>

tryToSeconds

Try to convert to seconds, returns null on failure.

Signature
int? tryToSeconds(dynamic value);
XML Usage
<Text data="${tryToSeconds(userInput)}"/>

tryToString

Try to convert to string, returns null on failure.

Signature
String? tryToString(dynamic value);
XML Usage
<Text data="${tryToString(userInput)}"/>