MCPcopy
hub / github.com/flet-dev/flet / App

Function App

sdk/python/examples/apps/studio_gallery/todo.py:157–212  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155
156@ft.component
157def App():
158 state, _ = ft.use_state(lambda: TodoAppState())
159 new_task_name, set_new_task_name = ft.use_state("")
160 new_task_field: ft.Ref = ft.Ref()
161
162 async def add_task():
163 state.add_task(new_task_name)
164 set_new_task_name("")
165 await cast(ft.TextField, new_task_field.current).focus()
166
167 return ft.Column(
168 [
169 Header(),
170 ft.Row(
171 controls=[
172 ft.TextField(
173 ref=new_task_field,
174 hint_text="What needs to be done?",
175 on_submit=add_task,
176 value=new_task_name,
177 on_change=lambda e: set_new_task_name(e.control.value),
178 autofocus=True,
179 expand=True,
180 ),
181 ft.FloatingActionButton(
182 icon=ft.Icons.ADD,
183 on_click=add_task,
184 ),
185 ],
186 ),
187 ft.Column(
188 spacing=25,
189 controls=[
190 ft.Tabs(
191 selected_index=state.statuses.index(state.status),
192 length=len(state.statuses),
193 on_change=state.status_changed,
194 content=ft.TabBar(
195 scrollable=False,
196 tabs=[ft.Tab(label=tab) for tab in state.statuses],
197 ),
198 ),
199 ft.Column(
200 [
201 TaskItemView(task, state.delete_task, key=task.id)
202 for task in state.get_tasks()
203 ]
204 ),
205 Footer(
206 active_tasks_number=state.active_tasks_number,
207 clear_completed=state.clear_completed,
208 ),
209 ],
210 ),
211 ]
212 )
213
214

Callers

nothing calls this directly

Calls 6

indexMethod · 0.80
TodoAppStateClass · 0.70
HeaderFunction · 0.70
TaskItemViewFunction · 0.70
FooterFunction · 0.70
get_tasksMethod · 0.45

Tested by

no test coverage detected