You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactored the filtering section in the To-Do app tutorial to clarify the use of Tabs and TabBar controls, update code examples for task creation and status change, and improve explanations for filtering tasks by status. Also fixed minor formatting and wording for better readability.
Copy file name to clipboardExpand all lines: sdk/python/packages/flet/docs/tutorials/todo.md
+28-35Lines changed: 28 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -138,7 +138,7 @@ Run the app and try to edit and delete tasks:
138
138
We already have a functional To-Do app where we can create, edit, and delete tasks.
139
139
To be even more productive, we want to be able to filter tasks by their status.
140
140
141
-
Copy the entire code for this step from [here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/todo/to-do-5.py).
141
+
Copy the entire code for this step from [here](https://github.com/flet-dev/flet/blob/main/sdk/python/examples/tutorials/todo/todo.py).
142
142
Below we will explain the changes we've done to implement filtering.
143
143
144
144
`Tabs` control is used to display filter:
@@ -148,18 +148,10 @@ Below we will explain the changes we've done to implement filtering.
148
148
149
149
classTodoApp(ft.Column):
150
150
# application's root control is a Column containing all other controls
151
-
def__init__(self):
152
-
super().__init__()
153
-
self.new_task = ft.TextField(hint_text="What's needs to be done?", expand=True)
151
+
definit(self):
152
+
self.new_task = ft.TextField(hint_text="Whats needs to be done?", expand=True)
154
153
self.tasks = ft.Column()
155
154
156
-
self.filter_tabs = ft.Tabs(
157
-
length=3,
158
-
selected_index=0,
159
-
on_change=lambdae: self.update(),
160
-
content=self.filter,
161
-
)
162
-
163
155
self.filter = ft.TabBar(
164
156
scrollable=False,
165
157
tabs=[
@@ -169,16 +161,19 @@ class TodoApp(ft.Column):
169
161
],
170
162
)
171
163
164
+
self.filter_tabs = ft.Tabs(
165
+
length=3,
166
+
selected_index=0,
167
+
on_change=lambdae: self.update(),
168
+
content=self.filter,
169
+
)
170
+
172
171
# ...
173
172
```
174
173
175
-
To display different lists of tasks depending on their statuses, we could maintain three
176
-
lists with "All", "Active" and "Completed" tasks. We, however, chose an easier approach
177
-
where we maintain the same list and only change a task's visibility depending on its status.
174
+
To display different lists of tasks depending on their statuses, we could maintain three lists with "All", "Active" and "Completed" tasks. We, however, chose an easier approach where we maintain the same list and only change a task's visibility depending on its status.
178
175
179
-
In `TodoApp` class we overrided [`before_update()`](../cookbook/custom-controls.md#before_update)
180
-
method alled every time when the control is being updated. It iterates through all the tasks and updates their `visible`
181
-
property depending on the status of the task:
176
+
In `TodoApp` class we overrided [`before_update()`](../cookbook/custom-controls.md#before_update) method alled every time when the control is being updated. It iterates through all the tasks and updates their `visible` property depending on the status of the task:
182
177
183
178
```python title="todo.py"
184
179
classTodoApp(ft.Column):
@@ -195,8 +190,7 @@ class TodoApp(ft.Column):
195
190
)
196
191
```
197
192
198
-
Filtering should occur when we click on a tab or change a task status. `TodoApp.before_update()` method
199
-
is called when Tabs selected value is changed or Task item checkbox is clicked:
193
+
Filtering should occur when we click on a tab or change a task status. `TodoApp.before_update()` method is called when Tabs selected value is changed or Task item checkbox is clicked:
Our Todo app is almost complete now. As a final touch, we will add a footer (`Column` control)
241
-
displaying the number of incomplete tasks (`Text` control) and a "Clear completed" button.
234
+
Our Todo app is almost complete now. As a final touch, we will add a footer (`Column` control) displaying the number of incomplete tasks (`Text` control) and a "Clear completed" button.
0 commit comments