# Calling Functions

## *"Call Function"* Action

Actions are meant to make the UI more functional. Using actions, you can navigate to a different page, change state of a widget, launch URLs, etc. In this case, we need to call a custom function in the SDK. So, we use the *Call Function* action.

Head over to *Develop Tab* located in the app bar.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2FTtwUJ6SpXEW9T7JutrXO%2Fimage.png?alt=media&#x26;token=bd9b436e-af53-4dd9-b0e3-80173e9d3f25" alt=""><figcaption><p>Develop Tab</p></figcaption></figure>

You should see the *Actions Panel* in the right. Now, select the node you wish to add the action to.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2FnUPjv4rHhrlevnknDbPe%2Fimage.png?alt=media&#x26;token=20b70967-4c5b-4c56-8eeb-582e37f3486b" alt=""><figcaption><p>Node selected</p></figcaption></figure>

To add an action, tap on the *add icon* and select *"Call Function Action"* from the dropdown.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2F7As2hrySRJgahgeGD3hz%2Fimage.png?alt=media&#x26;token=afe3fefe-7c57-412d-b4f5-78f5198b3576" alt=""><figcaption><p>Adding Call Function Action</p></figcaption></figure>

Next, tap on the *settings icon* to open the settings window.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2FwYL1rZ3hQmBkYDOADGCx%2Fimage.png?alt=media&#x26;token=4abae843-7545-460d-afc3-da2b506a9691" alt=""><figcaption><p>Action Settings Window</p></figcaption></figure>

Enter the custom function's name in the *Function Name Field*.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2FGM6nKgdzwXMvddARjEoh%2Fimage.png?alt=media&#x26;token=a8b51edb-732c-48af-9772-f5a00d5aceed" alt=""><figcaption><p>Function Name Field</p></figcaption></figure>

Action to call a custom function is now added to the node. Now, we need to provide the function in the SDK.

## Functions Field

We can provide custom functions to the `CodelesslyWidget` using its `functions` parameter which is of type `Map<String, CodelesslyFunction<T>>`. Map's key is the name of the function and value is `CodelesslyFunction` class that takes in the function itself in its constructor.

`CodelesslyFunction` has a parameter `call` which is a function with generic return type `T`. Here's an example of how we can declare functions in the widget.

```dart
CodelesslyWidget(
  functions: {
    'expandForecastPage': CodelesslyFunction((context, ref, params) {...}),
  }
);
```

`ref` is an instance of `CodelesslyContext` that you may use to access data and other functions from the SDK.

`params` is a Map that contains any parameters passed by the function when it is called. These parameters can be defined on the function call from the Editor.

<figure><img src="https://3474078512-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fx4NeiXalJWaOaV6tsK5f%2Fuploads%2FOCqo0FumsBeo6UqXHSKo%2Fimage.png?alt=media&#x26;token=c28445e9-1133-4bc2-a30c-a2ee8dbda8f7" alt=""><figcaption></figcaption></figure>

Now, node can access the function and call it on relevant trigger (*click* in this case).
