Complete the HomePage Layout
In this task, you will complete the layout of the HomePage.
To complete the HomePage layout, we have to define the general settings of the CheckboxListTile and the widgets inside it.
Select the CheckboxListTile and in the Settings Panel, click on the Function button of the Value field.
Change the From Value to Generated Variable. The Generated Variable comes from the Data Source we have set in ListView. So, for each value in taskList, it can check its properties.
The Generated Variable insert is now red because we didn't set a a value.
Click on it and fill the field with itemTaskList -> Task and isDone -> bool. Here we set the value of the CheckboxListTile to True if the field isDone in a task is True, and False otherwise.
Search the field Tile Color and set your desired color (#FFFFFFFF in the example).
Search the field Control Affinity and set it to Leading.
Search the field Checkbox Shape, enable it and set the shape to Circle.
We are going to set the color of the leading circle icon depending on the Priority property in our Task. ( 1 being high, 2 being medium, 3 being low and 0 being default/none).
Search for the field Side (Beware to not choose the Side field inside Checkbox Shape) and enable it. Inside it, click on the Function button of the field Color.
Change the From Value to Conditional Value.
Click on Add Conditional Value.
Open the Condition 0 created and fill, below the IF block, the field that define if it's a Single or Multiple condition to Single.
In the First Value insert, change the From Value to Generated Variable and select the itemTaskList -> Task and priority -> int? inside.
Let the Equal To condition type.
In the Second Value insert, set the From Value to 1.
In the Then insert, set the From Value to the color desired (name Error in the example).
Click on Save.
Repeat the step 10-16 with the From Value from Second Value to 2 and the From Value from Then to the color desired (#FFFF6E40 in the example).
Repeat the step 10-16 with the From Value from Second Value to 3 and the From Value from Then to the color desired (#FF33AA23 in the example).
Set the Default Value to On Surface.
Click on Save.
In the Local State you can add some Default Value to the taskList and fill the field with different value to watch on a simulator or a device the different Conditional Value you have set.
You can see the different color on the check icon you have set in the conditional value of the CheckboxListTile Value.
The next step is to set the value of the other fields of our Tasks, i.e the Title, Subtitle, Date, Comments icon and number, and Edit Button.
If you want to see some value in the Application Preview instead of a simulator/device, you can add a Preview Value by clicking on the Preview button when hovering a field.
Title
Select the Text inside CheckboxListTile>Title.
Click on the Function button of the field Text.
Change the From Value to Generated Variable.
Set the fields with itemTaskList -> Task and title -> String.
Click on Save.
Set a Padding of 10 on the Top.
Set Ellipsis in Overflow.
If you run again the project on your simulator/device you will see an update of the title of the default value.
You should now have the same result as shown below.
Subtitle
Select the Column inside CheckboxListTile>Subtitle and set the Cross Axis Alignment to Start.
Select the Text inside CheckboxListTile>Subtitle>Column.
Click on the Function button of the field Text.
Change the From Value to Generated Variable.
Set the fields with itemTaskList -> Task and title -> String.
In Default Value select Static.
Click on Save.
You should now have the same result as shown below.
Date
Because we want to show the Date with a precise format, we have to create a Custom Function.
Click on the Custom Functions tab.
Click on Add and choose Functions.
Fill the Name of the function with "dateTimeToString".
Set a parameter "dateTime" with a Field Type of DateTime.
Let the return type as String.
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.
Select the Row inside CheckboxListTile>Subtitle>Column and add a Padding of 10 on Top.
Select the Text inside CheckboxListTile>Subtitle>Column>Row>Flexible.
Click on the Function button of the field Text.
Change the From Value to Custom Function.
Select dateTimeToString.
Click on the Function button of the Parameters insert.
Change From Value to Generated Variable.
Click on the Function button of the dateTime parameter.
Select itemTaskList -> Task and date -> DateTime.
Click on Save.
The date is now well formatted and displayed but it lacks some colors to quickly see the priority.
Enable Text Style.
Click on the Function button of Text Color.
Set the same Conditional Value as the one you did in the steps 9-20 in the CheckboxListTile widget in the beginning of this task.
You should now have the same result as shown below.
Comment Icon and Text
Select the Icon inside CheckboxListTile>Subtitle>Column>Row.
Set a Padding of 5 on the Left and Right.
Enable Conditional Visibility and set a Single condition which if the field comments -> List<String> in Generated Variable IS NOT EMPTY.
Click on the Icon and search for Comment.
Set a size of 18.
Set Outline as Color.
We have to create a custom function to retrieve the length of the comments list to show it next to the previous Icon.
Click on the Custom Functions tab.
Click on Add and choose Functions.
Fill the Name of the function with "getListLength".
Set a parameter "list" with a Field Type of List<String>.
Set the return type as int.
Set the following code to complete the function :
We can now use this function everywhere in the application.
Select the Text inside CheckboxListTile>Subtitle>Column>Row.
Click on the function button of the field Text.
Set a Conditional Value that evaluates a single condition : IF the field comments -> List<String> in Generated Variable IS NOT EMPTY THEN the return value is the Custom Function with said comments -> List<String> in parameter.
In Default Value select Static.
Click on Save.
Enable TextStyle, inside set a FontSize of 14 and a TextColor of Outline.
You should now have the same result as shown below.
Edit button
Select the IconButton inside CheckboxListTile>Secondary.
Set the Name as "editButton".
Set the Icon as Edit and the Color as Primary.
You should now have the same result as shown below.
Now that the HomePage layout is completed, the next step is to add some actions in it !
Last updated