Skip to content

Commit 03035c7

Browse files
authored
Inesa/v1 docstrings (#5285)
* Docstrings and default values for IconButton * remove ListTile example * docstrings for ListTile * ListTile, MenuBar * MenuItemButton * NavigationBar * NavigationDrawer * Delete a.txt
1 parent f95f561 commit 03035c7

File tree

8 files changed

+725
-139
lines changed

8 files changed

+725
-139
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class _MenuItemButtonControlState extends State<MenuItemButtonControl> {
7777
: null,
7878
leadingIcon: widget.control.buildWidget("leading"),
7979
trailingIcon: widget.control.buildWidget("trailing_icon"),
80-
child: widget.control.buildWidget("content"),
80+
child: widget.control.buildTextOrWidget("content"),
8181
);
8282

8383
var focusValue = widget.control.getString("focus");

sdk/python/packages/flet/src/flet/controls/material/icon_button.py

Lines changed: 176 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
@control("IconButton")
2727
class IconButton(ConstrainedControl, AdaptiveControl):
2828
"""
29-
An icon button is a round button with an icon in the middle that reacts to touches by filling with color (ink).
29+
An icon button is a round button with an icon in the middle that reacts to touches
30+
by filling with color (ink).
3031
31-
Icon buttons are commonly used in the toolbars, but they can be used in many other places as well.
32+
Icon buttons are commonly used in the toolbars, but they can be used in many other
33+
places as well.
3234
3335
Online docs: https://flet.dev/docs/controls/iconbutton
3436
"""
@@ -44,35 +46,205 @@ def __setattr__(self, name, value):
4446
super().__setattr__(name, value)
4547

4648
icon: Optional[IconValueOrControl] = None
49+
"""
50+
Icon shown in the button.
51+
"""
52+
4753
icon_color: OptionalColorValue = None
54+
"""
55+
Icon [color](https://flet.dev/docs/reference/colors).
56+
"""
57+
4858
icon_size: OptionalNumber = None
49-
selected: bool = False
59+
"""
60+
Icon size in virtual pixels.
61+
62+
Defaults to `24`.
63+
"""
64+
65+
selected: Optional[bool] = None
66+
"""
67+
The optional selection state of the icon button.
68+
69+
If this property is not set, the button will behave as a normal push button,
70+
otherwise, the button will toggle between showing `icon` and `selected_icon` based
71+
on the value of `selected`.
72+
73+
If True, it will show `selected_icon`, if False it will show `icon`.
74+
"""
75+
5076
selected_icon: Optional[IconValueOrControl] = None
77+
"""
78+
Icon shown in the button in selected state.
79+
"""
80+
5181
selected_icon_color: OptionalColorValue = None
82+
"""
83+
Icon [color](https://flet.dev/docs/reference/colors) for the selected state.
84+
85+
An example of icon toggle button:
86+
87+
<img src="/img/blog/gradients/toggle-icon-button.gif" className="screenshot-10" />
88+
89+
```python
90+
import flet as ft
91+
92+
def main(page: ft.Page):
93+
94+
def toggle_icon_button(e):
95+
e.control.selected = not e.control.selected
96+
97+
page.add(
98+
ft.IconButton(
99+
icon=ft.Icons.BATTERY_1_BAR,
100+
selected_icon=ft.Icons.BATTERY_FULL,
101+
on_click=toggle_icon_button,
102+
selected=False,
103+
style=ft.ButtonStyle(
104+
color={"selected": ft.Colors.GREEN, "": ft.Colors.RED},
105+
),
106+
)
107+
)
108+
109+
ft.app(main)
110+
```
111+
"""
112+
52113
bgcolor: OptionalColorValue = None
114+
"""
115+
TBD
116+
"""
117+
53118
highlight_color: OptionalColorValue = None
119+
"""
120+
The button's [color](https://flet.dev/docs/reference/colors) when the button is
121+
pressed. The highlight fades in quickly as the button is held down.
122+
"""
123+
54124
style: Optional[ButtonStyle] = None
125+
"""
126+
Value is of type [`ButtonStyle`](https://flet.dev/docs/reference/types/buttonstyle).
127+
"""
128+
55129
autofocus: bool = False
130+
"""
131+
True if the control will be selected as the initial focus. If there is more than
132+
one control on a page with autofocus set, then the first one added to the page will
133+
get focus.
134+
"""
135+
56136
disabled_color: OptionalColorValue = None
137+
"""
138+
The [color](https://flet.dev/docs/reference/colors) to use for the icon inside the
139+
button when disabled.
140+
"""
141+
57142
hover_color: OptionalColorValue = None
143+
"""
144+
The button's [color](https://flet.dev/docs/reference/colors) when hovered.
145+
"""
146+
58147
focus_color: OptionalColorValue = None
148+
"""
149+
The button's [color](https://flet.dev/docs/reference/colors) when in focus.
150+
"""
151+
59152
splash_color: OptionalColorValue = None
153+
"""
154+
The primary [color](https://flet.dev/docs/reference/colors) of the button when the
155+
button is in the down (pressed) state.
156+
"""
157+
60158
splash_radius: OptionalNumber = None
159+
"""
160+
The splash radius. Honoured only when in Material 2.
161+
"""
162+
61163
alignment: Optional[Alignment] = None
164+
"""
165+
Defines how the icon is positioned within the IconButton. Alignment is an instance
166+
of [`Alignment`](https://flet.dev/docs/reference/types/alignment) class.
167+
168+
Defaults to `alignment.center`.
169+
"""
170+
62171
padding: OptionalPaddingValue = None
63-
enable_feedback: Optional[bool] = True
172+
"""
173+
Defines the padding around this button. The entire padded icon will react to input
174+
gestures.
175+
176+
Value is of type [`Padding`](https://flet.dev/docs/reference/types/padding) and
177+
defaults to `Padding.all(8)`.
178+
"""
179+
180+
enable_feedback: Optional[bool] = None
181+
"""
182+
Whether detected gestures should provide acoustic and/or haptic feedback.
183+
On Android, for example, setting this to `True` produce a click sound and a
184+
long-press will produce a short vibration.
185+
"""
186+
64187
url: Optional[str] = None
188+
"""
189+
The URL to open when the button is clicked. If registered, `on_click` event is fired
190+
after that.
191+
"""
192+
65193
url_target: Optional[UrlTarget] = None
194+
"""
195+
Where to open URL in the web mode.
196+
197+
Value is of type [`UrlTarget`](https://flet.dev/docs/reference/types/urltarget).
198+
"""
199+
66200
mouse_cursor: Optional[MouseCursor] = None
201+
"""
202+
The cursor to be displayed when a mouse pointer enters or is hovering over this
203+
control.
204+
205+
Value is of type [`MouseCursor`](https://flet.dev/docs/reference/types/mousecursor).
206+
"""
207+
67208
visual_density: Optional[VisualDensity] = None
209+
"""
210+
Defines how compact the control's layout will be.
211+
212+
Value is of type [`VisualDensity`](https://flet.dev/docs/reference/types/visualdensity).
213+
"""
214+
68215
size_constraints: Optional[BoxConstraints] = None
216+
"""
217+
TBD
218+
"""
219+
69220
on_click: OptionalControlEventCallable = None
221+
"""
222+
Fires when a user clicks the button.
223+
"""
224+
70225
on_focus: OptionalControlEventCallable = None
226+
"""
227+
Fires when the control has received focus.
228+
"""
229+
71230
on_blur: OptionalControlEventCallable = None
231+
"""
232+
Fires when the control has lost focus.
233+
"""
234+
72235
content: Optional[Control] = None # todo(0.70.3): remove in favor of icon
236+
"""
237+
A Control representing custom button content.
238+
"""
73239

74240
async def focus_async(self):
241+
"""
242+
Moves focus to a button.
243+
"""
75244
await self._invoke_method_async("focus")
76245

77246
def focus(self):
247+
"""
248+
Moves focus to a button.
249+
"""
78250
asyncio.create_task(self.focus_async())

0 commit comments

Comments
 (0)