Skip to content

Commit 1c63ae4

Browse files
committed
Add icon button variants and expand integration tests
Introduces a Python example for IconButton variants, including normal, disabled, and toggle states. Expands integration tests to cover disabled, selected, and unselected states for standard, filled, filled tonal, and outlined icon buttons, with corresponding golden images for macOS. Minor code cleanups and docstring updates are also included.
1 parent 3ceafc8 commit 1c63ae4

File tree

23 files changed

+217
-26
lines changed

23 files changed

+217
-26
lines changed

packages/flet/lib/src/controls/icon_button.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _IconButtonControlState extends State<IconButtonControl>
8080
widget.control.getBoxConstraints("size_constraints");
8181
var autofocus = widget.control.getBool("autofocus", false)!;
8282
var enableFeedback = widget.control.getBool("enable_feedback", true)!;
83-
var selected = widget.control.getBool("selected", false)!;
83+
var selected = widget.control.getBool("selected");
8484
var mouseCursor = widget.control.getMouseCursor("mouse_cursor");
8585
var url = widget.control.getUrl("url");
8686

packages/flet/lib/src/controls/view.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -253,28 +253,6 @@ class _ViewControlState extends State<ViewControl> {
253253
child: scaffold);
254254
}
255255

256-
if (pageData?.widgetsDesign == PageDesign.material) {
257-
scaffold = CupertinoTheme(
258-
data: pageData?.themeMode == ThemeMode.light ||
259-
((pageData?.themeMode == null ||
260-
pageData?.themeMode == ThemeMode.system) &&
261-
pageData?.brightness == Brightness.light)
262-
? parseCupertinoTheme(
263-
control.parent!.get("theme"), context, Brightness.light)
264-
: control.parent!.getString("dark_theme") != null
265-
? parseCupertinoTheme(
266-
control.parent!.get("dark_theme"), context, Brightness.dark)
267-
: parseCupertinoTheme(
268-
control.parent!.get("theme"), context, Brightness.dark),
269-
child: scaffold,
270-
);
271-
} else if (pageData?.widgetsDesign == PageDesign.cupertino) {
272-
scaffold = Theme(
273-
data: materialTheme,
274-
child: scaffold,
275-
);
276-
}
277-
278256
var showAppStartupScreen =
279257
FletBackend.of(context).showAppStartupScreen ?? false;
280258
var appStartupScreenMessage =
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import flet as ft
2+
3+
4+
def main(page: ft.Page):
5+
page.title = "IconButton variants"
6+
page.padding = 10
7+
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
8+
page.vertical_alignment = ft.MainAxisAlignment.CENTER
9+
10+
def toggle_icon_button(e):
11+
e.control.selected = not e.control.selected
12+
13+
page.add(
14+
ft.Row(
15+
alignment=ft.MainAxisAlignment.CENTER,
16+
spacing=50,
17+
controls=[
18+
# Normal buttons column (enabled only)
19+
ft.Column(
20+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
21+
spacing=20,
22+
controls=[
23+
ft.Text(
24+
"Normal",
25+
theme_style=ft.TextThemeStyle.BODY_MEDIUM,
26+
),
27+
ft.IconButton(
28+
icon=ft.Icons.FILTER_DRAMA,
29+
),
30+
ft.FilledIconButton(
31+
icon=ft.Icons.FILTER_DRAMA,
32+
),
33+
ft.FilledTonalIconButton(
34+
icon=ft.Icons.FILTER_DRAMA,
35+
),
36+
ft.OutlinedIconButton(
37+
icon=ft.Icons.FILTER_DRAMA,
38+
),
39+
],
40+
),
41+
# Disabled buttons column
42+
ft.Column(
43+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
44+
spacing=20,
45+
controls=[
46+
ft.Text(
47+
"Disabled",
48+
theme_style=ft.TextThemeStyle.BODY_MEDIUM,
49+
),
50+
ft.IconButton(
51+
icon=ft.Icons.FILTER_DRAMA,
52+
disabled=True,
53+
),
54+
ft.FilledIconButton(
55+
icon=ft.Icons.FILTER_DRAMA,
56+
disabled=True,
57+
),
58+
ft.FilledTonalIconButton(
59+
icon=ft.Icons.FILTER_DRAMA,
60+
disabled=True,
61+
),
62+
ft.OutlinedIconButton(
63+
icon=ft.Icons.FILTER_DRAMA,
64+
disabled=True,
65+
),
66+
],
67+
),
68+
# Toggle buttons column
69+
ft.Column(
70+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
71+
spacing=20,
72+
controls=[
73+
ft.Text(
74+
"Toggle",
75+
theme_style=ft.TextThemeStyle.BODY_MEDIUM,
76+
),
77+
ft.IconButton(
78+
icon=ft.Icons.FILTER_DRAMA,
79+
selected=False,
80+
on_click=toggle_icon_button,
81+
),
82+
ft.FilledIconButton(
83+
icon=ft.Icons.FILTER_DRAMA,
84+
selected=False,
85+
on_click=toggle_icon_button,
86+
),
87+
ft.FilledTonalIconButton(
88+
icon=ft.Icons.FILTER_DRAMA,
89+
selected=False,
90+
on_click=toggle_icon_button,
91+
),
92+
ft.OutlinedIconButton(
93+
icon=ft.Icons.FILTER_DRAMA,
94+
selected=False,
95+
on_click=toggle_icon_button,
96+
),
97+
],
98+
),
99+
],
100+
),
101+
)
102+
103+
104+
ft.run(main)

sdk/python/packages/flet/integration_tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pathlib import Path
22

3-
import flet.testing as ftt
43
import pytest_asyncio
54

5+
import flet.testing as ftt
6+
67

78
@pytest_asyncio.fixture(scope="module")
89
async def flet_app(request):
-2.5 KB
Loading
-28 Bytes
Loading
1.89 KB
Loading
1.93 KB
Loading
-78 Bytes
Loading
1.89 KB
Loading

0 commit comments

Comments
 (0)