> For the complete documentation index, see [llms.txt](https://docs.goril.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.goril.app/cookbook/my-first-application/add-actions-in-edittask-component.md).

# Add Actions in EditTask component

In this task, you will add all the actions mandatory to correctly edit a task.

In order to update a task, we first have to ensure our widgets interacts well together.

To update a task we have to make sure the EditTask component is opened with a Task in parameter and the modification update the global layout of the view.

1. Select the top widget **EditTask** and add a **Parameter** named "task" of **Type Task.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2Fp3HI9KkGqBYcZi8ASi7C%2F123.png?alt=media&amp;token=80bed8d1-b6a5-484b-bf71-d7bb9e10feae" alt="" width="375"><figcaption><p>EditTask task parameter</p></figcaption></figure>

2. Add an **Observable** named "taskObs" with **Field** **Type Task.**\
   Set the **Default Value** of **title** to "Default", of **date** to **Now** in **DateFormat** dropdown, of **isDone** to **False,** of **comments** to an empty list by clicking on **Add Value** then deleting the **value 0.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FHjLqoE6yYQyzGDRTHnRe%2F1234.png?alt=media&amp;token=207bcdec-cf1f-4d05-9e91-6e3ce6360293" alt="" width="375"><figcaption><p>EditTask taskObs observable</p></figcaption></figure>

3. Select the widget **title** and set an **Initial Value** of **Observable taskObs -> (Task) title.**
4. Select the widget **description** and set an **Initial Value** of **Observable taskObs -> (Task) description.**
5. Select the widget **date** and set an **Initial Value** of **Observable taskObs -> (Task) date.**
6. Select the widget **priority** and set an **Initial Value** of a **Conditional Value** that evaluates the value of **Observable taskObs -> (Task) priority** value to set a **Static From Value** of it.\
   The **priority** can have the values **1, 2, 3** or a **Default Value** of **0.** (see capture below).

<div><figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2Fo9nzaLAJUV0DSitFOV0G%2F12345.png?alt=media&amp;token=51ef188b-18a6-4364-8f41-142c3a42acb3" alt=""><figcaption><p>priority Initial Value Conditional Value</p></figcaption></figure> <figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FAszraNleOHcuNjuoIOws%2F12341234.png?alt=media&amp;token=4051a75d-19c7-4782-bacb-f6a63ce937b1" alt=""><figcaption><p>priority Initial Value Conditional Value</p></figcaption></figure></div>

7. Select the **Column** and set a **Conditional Visibility** to **True** if the **Observable taskObs -> (Task) comments Is Not Empty.** \
   In the **Generate Children** tab, set the **Data Source** as **Observable taskObs -> (Task) comments.**\
   Select the **Text** inside and set the **Text** as **Combined Text** with two **Sources** : "-" and the **Generated Variable comments -> String.**

The layout is correctly updating itself on changes, now you need to add actions to the component.

8. Add an **Action** to **EditTask** component named "setObs" that **Set Observable taskObs - (Task)** with the **task -> Task** from the **Parameters.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FHCSAuanaS19BSaKkWqK6%2F2233.png?alt=media&amp;token=8a53d5e4-0ee8-42a7-bcee-2c2140dfec35" alt=""><figcaption><p>Init EditTask observable</p></figcaption></figure>

9. Add an **Action** to **cancelButton** that **Navigate Back.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FUJtFcQ67jRIwepaMNE7q%2Factioncancel.png?alt=media&amp;token=1dcdf67e-51c0-4238-b0fa-c2adb64e6495" alt=""><figcaption><p>Action on cancelButton</p></figcaption></figure>

10. Add a **Conditional** **Action** to **saveButton** that evaluates the **Widget State Form form.**\
    In the **True** branch, add an **Action** "save" **Navigate Back** that **Return a Task Value From Value.**\
    The **title** is the value of the **Widget State title Force Not Null.**\
    The **date** is the value of the **Widget State date Force Not Null.**\
    The **description** is the value of the **Widget State description.**\
    The **isDone** is the value of the **Observable taskObs -> (Task) isDone.**\
    The **priority** is a **Conditional Value** that evaluates **IF** the **Widget State priority Is Not Null** then the value is the **Widget State priority Force Not Null.**\
    The **comments** is the value of the **Observable taskObs -> (Task) comments.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2Fe8sXr3fxenF14PowuXQN%2Fsavecon.png?alt=media&amp;token=2db779f9-42dc-4988-b6a8-a69bc394b491" alt=""><figcaption><p>saveButton Form condition</p></figcaption></figure>

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FYMra3JvwLGMFNfWP3l8D%2Fsaveva.png?alt=media&amp;token=7dc09b88-deb9-4ce7-905b-37e6c8c8e7e9" alt=""><figcaption><p>save action</p></figcaption></figure>

Before getting to the next step we have to add a **Custom Function** named "addComment", that takes **two** parameters : a **String comment** and a **Task task.** The **Return Type** is a **List\<String>.**

Between the two commented line add the following import :&#x20;

```dart
import 'package:todo_doc/models/models.dart';
```

Set the following code :&#x20;

```dart
  List<String> comments = List.of(task.comments);
  comments.add(comment);
  return comments;
```

We can now use this function everywhere in the application.

11. Add a **Conditional Action** to **addComment** that evaluates **IF** the **Widget State comment** **Is Not Empty.**\
    In the **True** branch add an **Action** named "updateTaskObservable" of **Type** **Set Observable,** the **Observable Source** is **taskObs - (Task),** the **Update Type** is **Set Value**.\
    The fields in **Update Source** are the same as 10. except for the **comments.**\
    In this case **comments** is a **Custom Function addComment -> List\<String>**, the parameter **comment** being the **Widget State comment Force Not Null** and the parameter **task** being the **Observable taskObs -> (Task).**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2F0rvnvggNRJL967h9rxsl%2Fcommentss.png?alt=media&amp;token=ac7d4a63-b836-472f-a19f-a8f5db91f7a8" alt=""><figcaption><p>addComment is not empty condition</p></figcaption></figure>

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FVr39yo1j0kcfj2Yyep2Q%2Fzzzz.png?alt=media&amp;token=485c1a2c-65ce-4e3b-8cb0-60338739f2a4" alt=""><figcaption><p>updateTaskObservable action</p></figcaption></figure>

Now, the EditTask component return a task and navigate back to the HomePage. But we have no action to actually open this component and handle the returned task.&#x20;

12. In the **HomePage** select the **editButton,** open the **Action Flow Editor** and create an action named "showEditTask" of **Type Show Bottom Sheet.** Select your **EditTask** component and set **Generated Variable itemTaskList -> Task** as **Parameters** and set a **Return Value** of type **Task?.** The return value is nullable because the user can cancel the bottom sheet without updating a task. Click on **Save** on the bottom on the panel.

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FTrRRsISLVYUExlwmAa1V%2Fzz.png?alt=media&amp;token=2280f8d4-9737-4e3c-8462-dd02c9e9d2e2" alt=""><figcaption><p>editButton showEditTask action</p></figcaption></figure>

13. Below add a **Condition** that evaluates **IF** the **Action Output** of **showEditTask->Task? IS NOT NULL.** Let the **Default Value** empty.

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FldnvTTkHtsmZ0O1w5EWo%2Fz1.png?alt=media&amp;token=f6733628-9c05-47b2-a05b-9c6a8a480bc5" alt=""><figcaption><p>showEditTask Action Output null condition</p></figcaption></figure>

14. In the **True** branch of the condition, add an action named "updateLocalState" of **Type Update Local State.** The **Update Local State Source** is your **taskList - (List\<Task>)** local state. Set the **Update Type** to **Update Item At Index,** the **Item Index** is **From Generated Index** and the **Update Source** to **Action Output showEditTask -> Task? Force To Null.**&#x20;

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2FtHqeouX2RxgQ2ybommoh%2Fz2.png?alt=media&amp;token=f57ed26b-51b2-4e7d-85b7-cbfbc2c45359" alt=""><figcaption><p>updateLocalState Action</p></figcaption></figure>

15. Add an action named "updateObservable" of type **Set Observable.** Set the **Observable Source** with your observable **taskList - (List\<Task>)** and the **Update Type** with **Set Value.** Set the **Update Source** to **Local State taskList -> List\<Task>.**

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2Fqp61oRKVDLRRfvgA5vXo%2Fz3.png?alt=media&amp;token=f7beb507-a35b-473a-a80f-3c94539659c6" alt=""><figcaption><p>updateObservable Action</p></figcaption></figure>

Now, you should be able to edit a task, and have the same result as shown below.

<figure><img src="https://2361990732-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FruhMqqOvKXgZPke0Ehds%2Fuploads%2F5x2QnfMQxqSt587Ta8AN%2FCleanShot%202023-06-08%20at%2014.07.37.gif?alt=media&amp;token=41bbc182-f7c4-4b63-b18c-c90db211896a" alt="" width="335"><figcaption><p>Edit a Task</p></figcaption></figure>

Congratulations ! You have completed the ToDo application tutorial !
