Add Update Task Action in HomePage
In this task, you will add the update task action in the HomePage.
Now that the layout is completed, you need to add your first action : update the isDone task property on click !
Click on the CheckboxListTile
The click on the CheckboxListTile will set the done status of the task.
To update a Task we need a Custom Function.
Create a Custom Function named "updateTask".
Set the Parameter task a Task.
Set the Return Type as Task.
Between the two commented line add the following import :
Set the following code to complete the function :
We can now use this function everywhere in the application.
Click on the CheckboxListTile and open the Action Flow Editor.
Add an Action with the name "update".
Set the Type to Update Local State.
Set the Update Local State Source to your taskList local state.
In the Update Type set Set Value.
Click on the Function button of the Update Source.
The Update Source is which data (i.e a list of task in this example) are we using to Set the Value in the local state. Select Custom Function and choose updateTask -> List<Task>.
The task parameters are LocalState taskList -> List<Task> and Generated Variable itemTaskList -> List<Task>.
Click on Save.
Below the Update action, click on the + and choose Add Condition.
The condition is Single and evaluates IF the Action Parameter selected -> bool? is Equal To From Value True.
The Action Parameter is a parameter induced by the component you are adding an action. In this case because it is a CheckboxListTile (so a Checkbox) the induced parameter is selected -> bool?
In a condition, the From Value is represented by a switch and true/false is the switch selected/unselected.
If the result of the condition is True, the task is done, we can show the user a congratulations message.
Below True, add an Action named "showSnackbar".
The Type of action is Show Snackbar.
Click on the Function button of the Message field.
Select Combined Text and click on Add below Sources.
Set the text to "Well Done !".
Add a second source with the Generated Variable itemTaskList title.
Add a third source with the text "is completed !".
Enable TextStyle.
Set the TextColor to your desired one (#FFFFFFFF in the example).
Set the Background color to your desired one (#FF33AA23 in the example).
Click on Save.
When clicked, your task is updated and your local state as well. But if you do not update the taskList observable you are not going to see any visual change beside the Snackbar.
Beneath the condition block, add an Action named "updateObservable".
Set the Type as Set Observable and choose your taskList observable.
In Item Index select Generated Index indexItemTaskList.
In Update Source select Local State and your taskList -> List<Task>.
Click on Save.
The action to set a task to Done/Undone is now complete. You should have the same result as shown below.
Now that you can update a task and set it as done/undone, the next step is to be able to create a task.
Last updated