diff --git a/packages/flet/lib/src/controls/container.dart b/packages/flet/lib/src/controls/container.dart index 3059836456..f55ae026da 100644 --- a/packages/flet/lib/src/controls/container.dart +++ b/packages/flet/lib/src/controls/container.dart @@ -199,9 +199,6 @@ class ContainerControl extends StatelessWidget with FletStoreMixin { container = IgnorePointer(child: container); } - return ConstrainedControl( - control: control, - child: container, - ); + return ConstrainedControl(control: control, child: container); } } diff --git a/packages/flet/lib/src/utils/buttons.dart b/packages/flet/lib/src/utils/buttons.dart index 0661e08a1f..106e2a8623 100644 --- a/packages/flet/lib/src/utils/buttons.dart +++ b/packages/flet/lib/src/utils/buttons.dart @@ -3,14 +3,15 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../models/control.dart'; -import '../utils/text.dart'; -import '../utils/theme.dart'; -import '../utils/time.dart'; -import '../utils/transforms.dart'; +import 'text.dart'; +import 'theme.dart'; +import 'time.dart'; +import 'transforms.dart'; import 'alignment.dart'; import 'borders.dart'; import 'colors.dart'; import 'edge_insets.dart'; +import 'geometry.dart'; import 'material_state.dart'; import 'mouse.dart'; import 'numbers.dart'; @@ -60,6 +61,9 @@ ButtonStyle? parseButtonStyle(dynamic value, ThemeData theme, iconSize: parseWidgetStateDouble(value["icon_size"]), visualDensity: parseVisualDensity(value["visual_density"]), mouseCursor: parseWidgetStateMouseCursor(value["mouse_cursor"]), + fixedSize: parseWidgetStateSize(value["fixed_size"]), + maximumSize: parseWidgetStateSize(value["maximum_size"]), + minimumSize: parseWidgetStateSize(value["minimum_size"]), ); } diff --git a/packages/flet/lib/src/utils/text.dart b/packages/flet/lib/src/utils/text.dart index 036d7d42fb..8ed752173c 100644 --- a/packages/flet/lib/src/utils/text.dart +++ b/packages/flet/lib/src/utils/text.dart @@ -210,7 +210,7 @@ WidgetStateProperty? parseWidgetStateTextStyle( WidgetStateProperty? defaultValue}) { if (value == null) return defaultValue; return getWidgetStateProperty( - value, (jv) => parseTextStyle(theme, jv), defaultTextStyle); + value, (jv) => parseTextStyle(jv, theme), defaultTextStyle); } extension TextParsers on Control { diff --git a/sdk/python/Taskfile.yml b/sdk/python/Taskfile.yml index a1f810bd61..97984620aa 100644 --- a/sdk/python/Taskfile.yml +++ b/sdk/python/Taskfile.yml @@ -15,7 +15,7 @@ tasks: setup: desc: "Setup environment by installing all pyproject.toml dependencies and pre-commit hooks." cmds: - - task: pyproject-setup + - task: install - task: pre-commit-install venv-init: @@ -25,22 +25,36 @@ tasks: cmds: - uv venv - tests: - desc: "Run unit tests." + unit-tests: + desc: "Run all unit tests." aliases: - test + - utest + - unit-test cmds: - uv run --group test pytest packages/flet/tests - control-tests: - desc: "Run integration tests for controls." + integration-tests: + desc: "Run all integration tests." + aliases: + - itest + - integration-test + cmds: + - uv run pytest -s -o log_cli=true -o log_cli_level=DEBUG packages/flet/integration_tests + + control-integration-tests: + desc: "Run all controls integration tests." + aliases: + - control-itest + - control-integration-test cmds: - uv run pytest -s -o log_cli=true -o log_cli_level=DEBUG packages/flet/integration_tests/controls - pyproject-setup: + install: desc: "Install all pyproject.toml dependencies present in 'all' dependency-group." aliases: - pyproject + - pyproject-setup cmds: - uv pip install -r pyproject.toml --group all diff --git a/sdk/python/packages/flet-cli/src/flet_cli/cli.py b/sdk/python/packages/flet-cli/src/flet_cli/cli.py index ba5c4fb274..62b50ad924 100644 --- a/sdk/python/packages/flet-cli/src/flet_cli/cli.py +++ b/sdk/python/packages/flet-cli/src/flet_cli/cli.py @@ -21,12 +21,11 @@ def set_default_subparser( This should be called after setting up the argument parser but before `parse_args()`. - Parameters: - - name (str): The name of the default subparser to use. - - args (list, optional): A list of arguments passed to `parse_args()`. Defaults - to None. - - index (int): Position in `sys.argv` where the default subparser should be - inserted. Defaults to 0. + Args: + name: The name of the default subparser to use. + args: A list of arguments passed to `parse_args()`. + index: Position in `sys.argv` where the default subparser should be + inserted. """ # exit if help or version flags are present diff --git a/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/elevated_button_basic.png b/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/basic.png similarity index 100% rename from sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/elevated_button_basic.png rename to sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/basic.png diff --git a/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style.png b/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style.png new file mode 100644 index 0000000000..2292af4559 Binary files /dev/null and b/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style.png differ diff --git a/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style_conflicts.png b/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style_conflicts.png new file mode 100644 index 0000000000..dbaebcba09 Binary files /dev/null and b/sdk/python/packages/flet/integration_tests/controls/golden/macos/elevated_button/button_style_conflicts.png differ diff --git a/sdk/python/packages/flet/integration_tests/controls/test_elevated_button.py b/sdk/python/packages/flet/integration_tests/controls/test_elevated_button.py index 0f90210e3f..b97b439a98 100644 --- a/sdk/python/packages/flet/integration_tests/controls/test_elevated_button.py +++ b/sdk/python/packages/flet/integration_tests/controls/test_elevated_button.py @@ -5,7 +5,7 @@ @pytest.mark.asyncio(loop_scope="module") -async def test_elevated_button_basic(flet_app: ftt.FletTestApp, request): +async def test_basic(flet_app: ftt.FletTestApp, request): flet_app.page.theme_mode = ft.ThemeMode.LIGHT await flet_app.assert_control_screenshot( request.node.name, @@ -32,3 +32,44 @@ async def test_issue_5538(flet_app: ftt.FletTestApp, request): ] ), ) + + +@pytest.mark.asyncio(loop_scope="module") +async def test_button_style(flet_app: ftt.FletTestApp, request): + flet_app.page.theme_mode = ft.ThemeMode.LIGHT + await flet_app.assert_control_screenshot( + request.node.name, + ft.ElevatedButton( + content="Test Button", + style=ft.ButtonStyle( + bgcolor=ft.Colors.BLUE, + shape=ft.RoundedRectangleBorder(radius=10), + side=ft.BorderSide(width=3, color=ft.Colors.YELLOW), + padding=ft.Padding.all(20), + text_style=ft.TextStyle( + size=15, + weight=ft.FontWeight.BOLD, + color=ft.Colors.WHITE, + ), + ), + ), + ) + + +@pytest.mark.asyncio(loop_scope="module") +async def test_button_style_conflicts(flet_app: ftt.FletTestApp, request): + flet_app.page.theme_mode = ft.ThemeMode.LIGHT + await flet_app.assert_control_screenshot( + request.node.name, + ft.ElevatedButton( + content="Test Button", + elevation=10, + color=ft.Colors.BLACK, + bgcolor=ft.Colors.BLUE, + style=ft.ButtonStyle( + elevation=2, + color=ft.Colors.WHITE, + bgcolor=ft.Colors.RED, + ), + ), + ) diff --git a/sdk/python/packages/flet/src/flet/controls/core/text_span.py b/sdk/python/packages/flet/src/flet/controls/core/text_span.py index 1df5ba501b..6501b67338 100644 --- a/sdk/python/packages/flet/src/flet/controls/core/text_span.py +++ b/sdk/python/packages/flet/src/flet/controls/core/text_span.py @@ -47,7 +47,7 @@ class TextSpan(Control): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.TextSpan.on_click] event callback is provided, + Additionally, if [`on_click`][flet.TextSpan.on_click] event callback is provided, it is fired after that. """ @@ -61,18 +61,20 @@ class TextSpan(Control): spell_out: Optional[bool] = None """ - Whether the assistive technologies should spell out this text character by character. + Whether the assistive technologies should spell out this text + character by character. - If the text is 'hello world', setting this to true causes the assistive technologies, - such as VoiceOver or TalkBack, to pronounce 'h-e-l-l-o-space-w-o-r-l-d' instead of complete words. + If the text is 'hello world', setting this to true causes the assistive + technologies, such as VoiceOver or TalkBack, to pronounce + 'h-e-l-l-o-space-w-o-r-l-d' instead of complete words. This is useful for texts, such as passwords or verification codes. If this span contains other text span children, they also inherit the property from this span unless explicitly set. - If the property is not set, this text span inherits the spell out setting from its parent. - If this text span does not have a parent or the parent does not have a spell out setting, - this text span does not spell out the text by default. + If the property is not set, this text span inherits the spell out setting + from its parent. If this text span does not have a parent or the parent does + not have a spell out setting, this text span does not spell out the text by default. """ on_click: Optional[ControlEventHandler["TextSpan"]] = None diff --git a/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_button.py b/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_button.py index b472e5a142..4c4f974b61 100644 --- a/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_button.py +++ b/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_button.py @@ -110,7 +110,7 @@ class CupertinoButton(ConstrainedControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.CupertinoButton.on_click] event callback is + Additionally, if [`on_click`][flet.CupertinoButton.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_list_tile.py b/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_list_tile.py index 000371e498..88aae3cded 100644 --- a/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_list_tile.py +++ b/sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_list_tile.py @@ -78,7 +78,7 @@ class CupertinoListTile(ConstrainedControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.CupertinoListTile.on_click] event callback is + Additionally, if [`on_click`][flet.CupertinoListTile.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/container.py b/sdk/python/packages/flet/src/flet/controls/material/container.py index c47b71815e..3063e7d047 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/container.py +++ b/sdk/python/packages/flet/src/flet/controls/material/container.py @@ -103,7 +103,8 @@ class Container(ConstrainedControl, AdaptiveControl): """ Defines how the [`content`][flet.Container.content] of the container is clipped. - Defaults to `ClipBehavior.ANTI_ALIAS` if [`border_radius`][flet.Container.border_radius] is not `None`; + Defaults to `ClipBehavior.ANTI_ALIAS` if + [`border_radius`][flet.Container.border_radius] is not `None`; otherwise `ClipBehavior.NONE`. """ @@ -180,7 +181,7 @@ class Container(ConstrainedControl, AdaptiveControl): """ The URL to open when this container is clicked. - Additionally, if [`on_click`][ft.Container.on_click] event callback is provided, + Additionally, if [`on_click`][flet.Container.on_click] event callback is provided, it is fired after that. """ @@ -241,7 +242,8 @@ def main(page: ft.Page): theme_mode: Optional[ThemeMode] = None """ "Resets" parent theme and creates a new, unique scheme for all - controls inside the container. Otherwise the styles defined in container's [`theme`][flet.Container.theme] + controls inside the container. Otherwise the styles defined in + container's [`theme`][flet.Container.theme] property override corresponding styles from the parent, inherited theme. Defaults to `ThemeMode.SYSTEM`. @@ -321,8 +323,8 @@ def on_tap_down(e: ft.ContainerTapEvent): """ Called when a mouse pointer enters or exists the container area. - The `data` property of the event handler argument is `True` when the cursor enters and - `False` when it exits. + The `data` property of the event handler argument is `True` + when the cursor enters and `False` when it exits. Example: A container changing its background color on mouse hover: diff --git a/sdk/python/packages/flet/src/flet/controls/material/elevated_button.py b/sdk/python/packages/flet/src/flet/controls/material/elevated_button.py index 6953836aba..3df80dcee8 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/elevated_button.py +++ b/sdk/python/packages/flet/src/flet/controls/material/elevated_button.py @@ -102,7 +102,7 @@ class ElevatedButton(ConstrainedControl, AdaptiveControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.ElevatedButton.on_click] event callback is + Additionally, if [`on_click`][flet.ElevatedButton.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/floating_action_button.py b/sdk/python/packages/flet/src/flet/controls/material/floating_action_button.py index 4d89ca0dd7..f63656b804 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/floating_action_button.py +++ b/sdk/python/packages/flet/src/flet/controls/material/floating_action_button.py @@ -144,7 +144,7 @@ class FloatingActionButton(ConstrainedControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.FloatingActionButton.on_click] event callback + Additionally, if [`on_click`][flet.FloatingActionButton.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/icon_button.py b/sdk/python/packages/flet/src/flet/controls/material/icon_button.py index d6ca32f026..f165a61f61 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/icon_button.py +++ b/sdk/python/packages/flet/src/flet/controls/material/icon_button.py @@ -197,7 +197,7 @@ def toggle_icon_button(e): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.IconButton.on_click] event callback is provided, + Additionally, if [`on_click`][flet.IconButton.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/list_tile.py b/sdk/python/packages/flet/src/flet/controls/material/list_tile.py index 134a5f6dfb..40e341f3a2 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/list_tile.py +++ b/sdk/python/packages/flet/src/flet/controls/material/list_tile.py @@ -184,7 +184,7 @@ class ListTile(ConstrainedControl, AdaptiveControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.ListTile.on_click] event callback is provided, + Additionally, if [`on_click`][flet.ListTile.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/outlined_button.py b/sdk/python/packages/flet/src/flet/controls/material/outlined_button.py index 5bebe71e02..29235a254d 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/outlined_button.py +++ b/sdk/python/packages/flet/src/flet/controls/material/outlined_button.py @@ -61,7 +61,7 @@ class OutlinedButton(ConstrainedControl, AdaptiveControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.OutlinedButton.on_click] event callback is + Additionally, if [`on_click`][flet.OutlinedButton.on_click] event callback is provided, it is fired after that. """ diff --git a/sdk/python/packages/flet/src/flet/controls/material/text_button.py b/sdk/python/packages/flet/src/flet/controls/material/text_button.py index 4ef555c68b..0d3714b0e1 100644 --- a/sdk/python/packages/flet/src/flet/controls/material/text_button.py +++ b/sdk/python/packages/flet/src/flet/controls/material/text_button.py @@ -56,7 +56,7 @@ class TextButton(ConstrainedControl, AdaptiveControl): """ The URL to open when this button is clicked. - Additionally, if [`on_click`][ft.TextButton.on_click] event callback is + Additionally, if [`on_click`][flet.TextButton.on_click] event callback is provided, it is fired after that. """ @@ -79,7 +79,7 @@ class TextButton(ConstrainedControl, AdaptiveControl): """ Called when a mouse pointer enters or exists this button's response area. - The [`data`][ft.Event.data] property of event object is `True` when cursor + The [`data`][flet.Event.data] property of event object is `True` when cursor enters and `False` when it exits. """ diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.toml index 4918150e8f..5b46844190 100644 --- a/sdk/python/pyproject.toml +++ b/sdk/python/pyproject.toml @@ -77,7 +77,7 @@ show-fixes = true [tool.ruff.lint] pydocstyle = { convention = 'google' } -isort = { known-first-party = ["flet"] } +isort = { known-first-party = ["flet", "flet_cli"] } preview = true select = [ # pycodestyle