Skip to content

Inesa/v1 docstrings #5285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/menu_item_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _MenuItemButtonControlState extends State<MenuItemButtonControl> {
: null,
leadingIcon: widget.control.buildWidget("leading"),
trailingIcon: widget.control.buildWidget("trailing_icon"),
child: widget.control.buildWidget("content"),
child: widget.control.buildTextOrWidget("content"),
);

var focusValue = widget.control.getString("focus");
Expand Down
180 changes: 176 additions & 4 deletions sdk/python/packages/flet/src/flet/controls/material/icon_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
@control("IconButton")
class IconButton(ConstrainedControl, AdaptiveControl):
"""
An icon button is a round button with an icon in the middle that reacts to touches by filling with color (ink).
An icon button is a round button with an icon in the middle that reacts to touches
by filling with color (ink).

Icon buttons are commonly used in the toolbars, but they can be used in many other places as well.
Icon buttons are commonly used in the toolbars, but they can be used in many other
places as well.

Online docs: https://flet.dev/docs/controls/iconbutton
"""
Expand All @@ -44,35 +46,205 @@ def __setattr__(self, name, value):
super().__setattr__(name, value)

icon: Optional[IconValueOrControl] = None
"""
Icon shown in the button.
"""

icon_color: OptionalColorValue = None
"""
Icon [color](https://flet.dev/docs/reference/colors).
"""

icon_size: OptionalNumber = None
selected: bool = False
"""
Icon size in virtual pixels.

Defaults to `24`.
"""

selected: Optional[bool] = None
"""
The optional selection state of the icon button.

If this property is not set, the button will behave as a normal push button,
otherwise, the button will toggle between showing `icon` and `selected_icon` based
on the value of `selected`.

If True, it will show `selected_icon`, if False it will show `icon`.
"""

selected_icon: Optional[IconValueOrControl] = None
"""
Icon shown in the button in selected state.
"""

selected_icon_color: OptionalColorValue = None
"""
Icon [color](https://flet.dev/docs/reference/colors) for the selected state.

An example of icon toggle button:

<img src="/img/blog/gradients/toggle-icon-button.gif" className="screenshot-10" />

```python
import flet as ft

def main(page: ft.Page):

def toggle_icon_button(e):
e.control.selected = not e.control.selected

page.add(
ft.IconButton(
icon=ft.Icons.BATTERY_1_BAR,
selected_icon=ft.Icons.BATTERY_FULL,
on_click=toggle_icon_button,
selected=False,
style=ft.ButtonStyle(
color={"selected": ft.Colors.GREEN, "": ft.Colors.RED},
),
)
)

ft.app(main)
```
"""

bgcolor: OptionalColorValue = None
"""
TBD
"""

highlight_color: OptionalColorValue = None
"""
The button's [color](https://flet.dev/docs/reference/colors) when the button is
pressed. The highlight fades in quickly as the button is held down.
"""

style: Optional[ButtonStyle] = None
"""
Value is of type [`ButtonStyle`](https://flet.dev/docs/reference/types/buttonstyle).
"""

autofocus: bool = False
"""
True if the control will be selected as the initial focus. If there is more than
one control on a page with autofocus set, then the first one added to the page will
get focus.
"""

disabled_color: OptionalColorValue = None
"""
The [color](https://flet.dev/docs/reference/colors) to use for the icon inside the
button when disabled.
"""

hover_color: OptionalColorValue = None
"""
The button's [color](https://flet.dev/docs/reference/colors) when hovered.
"""

focus_color: OptionalColorValue = None
"""
The button's [color](https://flet.dev/docs/reference/colors) when in focus.
"""

splash_color: OptionalColorValue = None
"""
The primary [color](https://flet.dev/docs/reference/colors) of the button when the
button is in the down (pressed) state.
"""

splash_radius: OptionalNumber = None
"""
The splash radius. Honoured only when in Material 2.
"""

alignment: Optional[Alignment] = None
"""
Defines how the icon is positioned within the IconButton. Alignment is an instance
of [`Alignment`](https://flet.dev/docs/reference/types/alignment) class.

Defaults to `alignment.center`.
"""

padding: OptionalPaddingValue = None
enable_feedback: Optional[bool] = True
"""
Defines the padding around this button. The entire padded icon will react to input
gestures.

Value is of type [`Padding`](https://flet.dev/docs/reference/types/padding) and
defaults to `Padding.all(8)`.
"""

enable_feedback: Optional[bool] = None
"""
Whether detected gestures should provide acoustic and/or haptic feedback.
On Android, for example, setting this to `True` produce a click sound and a
long-press will produce a short vibration.
"""

url: Optional[str] = None
"""
The URL to open when the button is clicked. If registered, `on_click` event is fired
after that.
"""

url_target: Optional[UrlTarget] = None
"""
Where to open URL in the web mode.

Value is of type [`UrlTarget`](https://flet.dev/docs/reference/types/urltarget).
"""

mouse_cursor: Optional[MouseCursor] = None
"""
The cursor to be displayed when a mouse pointer enters or is hovering over this
control.

Value is of type [`MouseCursor`](https://flet.dev/docs/reference/types/mousecursor).
"""

visual_density: Optional[VisualDensity] = None
"""
Defines how compact the control's layout will be.

Value is of type [`VisualDensity`](https://flet.dev/docs/reference/types/visualdensity).
"""

size_constraints: Optional[BoxConstraints] = None
"""
TBD
"""

on_click: OptionalControlEventCallable = None
"""
Fires when a user clicks the button.
"""

on_focus: OptionalControlEventCallable = None
"""
Fires when the control has received focus.
"""

on_blur: OptionalControlEventCallable = None
"""
Fires when the control has lost focus.
"""

content: Optional[Control] = None # todo(0.70.3): remove in favor of icon
"""
A Control representing custom button content.
"""

async def focus_async(self):
"""
Moves focus to a button.
"""
await self._invoke_method_async("focus")

def focus(self):
"""
Moves focus to a button.
"""
asyncio.create_task(self.focus_async())
Loading