Skip to content

Commit ff1d93f

Browse files
committed
Refactor DatePicker instantiation in example
Moves DatePicker creation outside the button click handler to reuse the same instance. This simplifies the code and avoids creating a new DatePicker object on each click.
1 parent 015722c commit ff1d93f

File tree

1 file changed

+8
-10
lines changed
  • sdk/python/examples/controls/date_picker

1 file changed

+8
-10
lines changed

sdk/python/examples/controls/date_picker/basic.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,18 @@ def handle_dismissal(e: ft.Event[ft.DialogControl]):
1414

1515
today = datetime.datetime.now()
1616

17+
d = ft.DatePicker(
18+
first_date=datetime.datetime(year=today.year - 1, month=1, day=1),
19+
last_date=datetime.datetime(year=today.year + 1, month=today.month, day=20),
20+
on_change=handle_change,
21+
on_dismiss=handle_dismissal,
22+
)
23+
1724
page.add(
1825
ft.Button(
1926
content="Pick date",
2027
icon=ft.Icons.CALENDAR_MONTH,
21-
on_click=lambda e: page.show_dialog(
22-
ft.DatePicker(
23-
first_date=datetime.datetime(year=today.year - 1, month=1, day=1),
24-
last_date=datetime.datetime(
25-
year=today.year + 1, month=today.month, day=20
26-
),
27-
on_change=handle_change,
28-
on_dismiss=handle_dismissal,
29-
)
30-
),
28+
on_click=lambda e: page.show_dialog(d),
3129
)
3230
)
3331

0 commit comments

Comments
 (0)