Skip to content

Commit 9be6a95

Browse files
committed
Refactor DateRangePicker instantiation in example
Moves DateRangePicker creation outside the button click handler to avoid redundant instantiation. The picker is now created once and reused when the button is clicked.
1 parent ff1d93f commit 9be6a95

File tree

1 file changed

+8
-12
lines changed
  • sdk/python/examples/controls/date_range_picker

1 file changed

+8
-12
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,18 @@ def handle_dismissal(e: ft.Event[ft.DialogControl]):
1919

2020
today = datetime.datetime.now()
2121

22+
drp = ft.DateRangePicker(
23+
start_value=datetime.datetime(year=today.year, month=today.month, day=1),
24+
end_value=datetime.datetime(year=today.year, month=today.month, day=15),
25+
on_change=handle_change,
26+
on_dismiss=handle_dismissal,
27+
)
28+
2229
page.add(
2330
ft.Button(
2431
content=ft.Text("Pick date"),
2532
icon=ft.Icons.PHONE,
26-
on_click=lambda e: page.show_dialog(
27-
ft.DateRangePicker(
28-
start_value=datetime.datetime(
29-
year=today.year, month=today.month, day=1
30-
),
31-
end_value=datetime.datetime(
32-
year=today.year, month=today.month, day=15
33-
),
34-
on_change=handle_change,
35-
on_dismiss=handle_dismissal,
36-
)
37-
),
33+
on_click=lambda e: page.show_dialog(drp),
3834
)
3935
)
4036

0 commit comments

Comments
 (0)