Skip to content

<callback>

This tag allows you to bind an event handler with custom arguments. If you don't need to pass any arguments, then just bind the handler using EL, like so: <TextButton onPressed="${onPressed}"/>. This is sufficient in most cases.

The callback tag creates an event handler function for you and executes the action when the event is triggered. action is an EL expression that is evaluated at the time of the event. Do not enclose the expression in curly braces ${...}, otherwise it will be evaluated immediately upon creation instead of when the event is fired.

If the handler function defines arguments in its signature, you must declare those arguments using the vars attribute. This attribute takes a comma separated list of argument names. When the handler is triggered, argument values are added to Dependencies using the specified name as the key, and can be referenced in the action EL expression, if needed. They're also accessible anywhere else that instance of Dependencies is available. If you don't need the values, then use and underscore (_) in place of the name. Doing so will ignore the values and they won't be added to Dependencies e.g. ...vars="_,index".... BuildContext is never added to Dependencies even when named, because this would cause a memory leak.

Attributes

Name Description Required Default
action The El expression to evaluate when the event handler is triggered. yes null
dependenciesScope Defines the method for passing Dependencies to immediate children. Valid values are new, copy, and inherit. no auto
for The name of the parent's attribute that will be assigned the event handler. yes null
returnVar The storage destination within Dependencies for the return value of action. no null
vars A comma separated list of handler function arguments. Values of named arguments are stored as dependencies. Supports up to five arguments. no null

Example

XML
<TextButton>
    <callback for="onPressed" action="doSomething('Hello World')"/>
    <Text>Press Me</Text>
</TextButton>