Skip to content

Commit fd461e4

Browse files
Minor fixes for control examples (#5831)
* Fix layout and doc formatting in canvas and bottomsheet Updated brush_on_image.py to remove invalid width and set expand on Stack for proper layout. Added a missing newline in bottomsheet.md for improved markdown formatting. * Update chart examples and dependencies Refactored chart and color examples for improved clarity and modern Python practices, including use of dataclasses and async clipboard handling. Enhanced custom scrollbar and infinite scrolling examples with more realistic content and fixed key usage. Updated documentation to require both 'plotly' and 'kaleido' for PlotlyChart. Added 'matplotlib', 'plotly', and 'kaleido' to dependencies in pyproject.toml. * Fix type and class usage in example scripts Updated scroll event handler to use generic OnScrollEvent type in column example. Replaced ft.border.all with ft.Border.all in nested container themes example for correct class usage. * Update Cupertino control examples for API changes Replaced deprecated usages in CupertinoButton and CupertinoRadio examples to match updated Flet API. Refactored CupertinoTimerPicker example to simplify timer value handling and fix event data usage. * Fix DataTable event handling and sorting logic Corrected color constant names and border usage in DataTable examples. Refactored sorting logic in datatable2 example to properly sort data and update table state, and fixed initialization of sorted data and DataTable2 instance. * 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. * 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. * Remove unused drag-and-drop example files Deleted ordering.py and outer_inner.py from the drag_target_and_draggable examples to clean up deprecated or redundant code. Also fixed a color constant typo in drag_and_drop_containers.py. * Add declarative drag-and-drop examples Added two new Python examples demonstrating declarative drag-and-drop: one for containers and one for ordering items and groups. Updated draggable.md documentation to reference the new declarative containers example. * Rename dropdown example and clean up code Renamed 'reactive.py' to 'declarative.py' for clarity. Removed unused logging setup from 'basic.py'. Fixed icon name reference in 'dropdown_random_icon.py' to use 'icon.icon' instead of 'icon.name'. * Fix ExpansionTile trailing icon property usage Replaces incorrect usage of 'name' with 'icon' for the trailing property in ExpansionTile event handlers. Also updates SnackBar text assignment for ruff formatting. * Update gesture detector event handling and cursor change Replaced usage of delta_x and delta_y with local_delta.x and local_delta.y in draggable_containers.py for more accurate drag updates. Simplified mouse cursor change logic in mouse_cursors.py by using random.choice instead of a generator. * Update image assets and fix control property usage Added app_icon_512.png and updated gallery.py to use the new image asset. Fixed property names and usage in static_svg.py, handling_events.py, and outlined_button/icons.py to use correct constants and class references for colors, margins, and icons. * Fix color constant in ButtonControl border Replaces 'ft.Colors.BLACK54' with 'ft.Colors.BLACK_54' to use the correct color constant for the button border. * Update event handlers to print control object Changed event handler print statements to output the control object instead of its uid for better debugging and information in rich text example. * Fix string formatting and color constant in text field examples Corrected multi-line string assignment in prefix_and_suffix.py to properly display textbox values. Updated styled.py to use the correct color constant 'BLACK_26' instead of 'BLACK26'. * Remove logging setup from drag and drop example Eliminated unnecessary logging configuration and logger level settings from the drag_and_drop_ordering_declarative.py example to simplify the code. * Move plotting libraries to dev dependencies matplotlib, plotly, and kaleido have been moved from main dependencies to dev dependencies in pyproject.toml. This reduces the default install footprint for end users and keeps plotting tools available for development and testing. --------- Co-authored-by: Feodor Fitsner <[email protected]>
1 parent 480335d commit fd461e4

File tree

41 files changed

+553
-517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+553
-517
lines changed

sdk/python/examples/apps/controls-gallery/examples/colors/themecolors/01_theme_colors.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
from dataclasses import dataclass
2+
13
import flet as ft
24

35
name = "Theme colors"
46

57

68
def example():
9+
@dataclass
710
class Color:
8-
def __init__(self, display_name, name, is_dark=False):
9-
self.name = name
10-
self.display_name = display_name
11-
self.is_dark = is_dark
11+
name: str
12+
display_name: str
13+
is_dark: bool = False
1214

1315
theme_colors = [
1416
Color("PRIMARY", "primary"),
@@ -40,9 +42,9 @@ def __init__(self, display_name, name, is_dark=False):
4042
Color("SCRIM", "scrim", True),
4143
]
4244

43-
def copy_to_clipboard(e):
44-
e.control.page.set_clipboard(f"ft.Colors.{e.control.content.value}")
45-
e.control.page.open(
45+
async def copy_to_clipboard(e):
46+
await e.control.page.clipboard.set(f"ft.Colors.{e.control.content.value}")
47+
e.control.page.show_dialog(
4648
ft.SnackBar(
4749
ft.Text(f"Copied to clipboard: ft.Colors.{e.control.content.value}"),
4850
open=True,

sdk/python/examples/controls/canvas/brush_on_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def handle_pan_update(e: ft.DragUpdateEvent):
3434
page.add(
3535
ft.Container(
3636
border_radius=5,
37-
width=float("inf"),
3837
expand=True,
3938
content=ft.Stack(
39+
expand=True,
4040
controls=[
4141
ft.Image(
4242
src="https://picsum.photos/200/300",
@@ -51,7 +51,7 @@ def handle_pan_update(e: ft.DragUpdateEvent):
5151
drag_interval=10,
5252
),
5353
),
54-
]
54+
],
5555
),
5656
)
5757
)

sdk/python/examples/controls/charts/line_chart/example_2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import flet_charts as fch
2-
31
import flet as ft
2+
import flet_charts as fch
43

54

65
class State:
@@ -134,7 +133,7 @@ def toggle_data(e: ft.Event[ft.ElevatedButton]):
134133
state.toggled = not state.toggled
135134
chart.update()
136135

137-
page.add(ft.ElevatedButton("avg", on_click=toggle_data), chart)
136+
page.add(ft.Button("avg", on_click=toggle_data), chart)
138137

139138

140139
ft.run(main)

sdk/python/examples/controls/charts/pie_chart/example_2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import flet_charts as fch
2-
31
import flet as ft
2+
import flet_charts as fch
43

54
NORMAL_RADIUS = 50
65
HOVER_RADIUS = 60
@@ -11,7 +10,7 @@
1110
size=22,
1211
color=ft.Colors.WHITE,
1312
weight=ft.FontWeight.BOLD,
14-
shadow=ft.BoxShadow(blur_radius=2, color=ft.Colors.BLACK54),
13+
shadow=ft.BoxShadow(blur_radius=2, color=ft.Colors.BLACK_54),
1514
)
1615

1716

sdk/python/examples/controls/column/custom_scrollbar.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,37 @@ def main(page: ft.Page):
2222
)
2323
)
2424

25-
# todo: finish example
25+
fake_messages = [
26+
ft.Container(
27+
ft.Text(f"Message {i}", size=16, weight=ft.FontWeight.W_500),
28+
bgcolor=ft.Colors.with_opacity(0.15, ft.Colors.BLUE_200),
29+
border_radius=8,
30+
padding=10,
31+
)
32+
for i in range(1, 31)
33+
]
34+
35+
page.add(
36+
ft.Row(
37+
[
38+
ft.Container(
39+
content=ft.Column(
40+
controls=fake_messages,
41+
spacing=10,
42+
scroll=ft.ScrollMode.ALWAYS,
43+
expand=True,
44+
),
45+
width=320,
46+
height=420,
47+
bgcolor=ft.Colors.with_opacity(0.15, ft.Colors.AMBER_200),
48+
padding=15,
49+
border_radius=12,
50+
)
51+
],
52+
alignment=ft.MainAxisAlignment.CENTER,
53+
expand=True,
54+
)
55+
)
2656

2757

2858
ft.run(main)

sdk/python/examples/controls/column/infinite_scrolling.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ class State:
1313

1414
def main(page: ft.Page):
1515
def on_scroll(e: ft.OnScrollEvent):
16-
if e.pixels >= e.max_scroll_extent - 100:
17-
if sem.acquire(blocking=False):
18-
try:
19-
for i in range(0, 10):
20-
cl.controls.append(
21-
ft.Text(f"Text line {s.i}", scroll_key=str(s.i))
22-
)
23-
s.i += 1
24-
cl.update()
25-
finally:
26-
sem.release()
16+
if e.pixels >= e.max_scroll_extent - 100 and sem.acquire(blocking=False):
17+
try:
18+
for _i in range(0, 10):
19+
cl.controls.append(ft.Text(f"Text line {s.i}", key=str(s.i)))
20+
s.i += 1
21+
cl.update()
22+
finally:
23+
sem.release()
2724

2825
cl = ft.Column(
2926
spacing=10,
@@ -33,8 +30,8 @@ def on_scroll(e: ft.OnScrollEvent):
3330
scroll_interval=0,
3431
on_scroll=on_scroll,
3532
)
36-
for i in range(0, 50):
37-
cl.controls.append(ft.Text(f"Text line {s.i}", scroll_key=str(s.i)))
33+
for _i in range(0, 50):
34+
cl.controls.append(ft.Text(f"Text line {s.i}", key=str(s.i)))
3835
s.i += 1
3936

4037
page.add(ft.Container(cl, border=ft.Border.all(1)))

sdk/python/examples/controls/column/scroll_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def main(page: ft.Page):
5-
def handle_column_scroll(e: ft.OnScrollEvent[ft.Column]):
5+
def handle_column_scroll(e: ft.OnScrollEvent):
66
print(e)
77

88
page.add(

sdk/python/examples/controls/container/nested_themes_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def main(page: ft.Page):
5252
ft.Container(
5353
padding=20,
5454
bgcolor=ft.Colors.SURFACE_TINT,
55-
border=ft.border.all(3, ft.Colors.OUTLINE),
55+
border=ft.Border.all(3, ft.Colors.OUTLINE),
5656
theme_mode=ft.ThemeMode.LIGHT,
5757
theme=ft.Theme(),
5858
content=ft.Row(
@@ -69,7 +69,7 @@ def main(page: ft.Page):
6969
ft.Container(
7070
padding=20,
7171
bgcolor=ft.Colors.SURFACE_TINT,
72-
border=ft.border.all(3, ft.Colors.OUTLINE),
72+
border=ft.Border.all(3, ft.Colors.OUTLINE),
7373
border_radius=10,
7474
theme_mode=ft.ThemeMode.SYSTEM,
7575
theme=ft.Theme(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main(page: ft.Page):
1515
ft.CupertinoButton(
1616
bgcolor=ft.Colors.PRIMARY,
1717
alignment=ft.Alignment.TOP_LEFT,
18-
border_radius=ft.border_radius.all(15),
18+
border_radius=ft.BorderRadius.all(15),
1919
opacity_on_click=0.5,
2020
on_click=lambda e: print("Filled CupertinoButton clicked!"),
2121
content=ft.Text("Filled CupertinoButton", color=ft.Colors.YELLOW),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def handle_button_click(e: ft.Event[ft.ElevatedButton]):
3030
]
3131
)
3232
),
33-
ft.ElevatedButton(content="Submit", on_click=handle_button_click),
33+
ft.Button(content="Submit", on_click=handle_button_click),
3434
message := ft.Text(),
3535
)
3636

0 commit comments

Comments
 (0)