Skip to content
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

fix: prevent button style from being modified in before_update() #4181

Merged
merged 4 commits into from
Oct 17, 2024
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
7 changes: 4 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from flet_core.types import (
BorderRadiusValue,
ControlState,
PaddingValue,
MouseCursor,
Number,
PaddingValue,
VisualDensity,
MouseCursor,
)


Expand All @@ -35,7 +35,8 @@ def __post_init__(self):

@dataclass
class CircleBorder(OutlinedBorder):
type: str = field(default="circle")
def __post_init__(self):
self.type = "circle"


@dataclass
Expand Down
33 changes: 13 additions & 20 deletions sdk/python/packages/flet-core/src/flet_core/elevated_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ def __init__(

AdaptiveControl.__init__(self, adaptive=adaptive)

self.__color = None
self.__bgcolor = None
self.__elevation = None

self.text = text
self.color = color
self.bgcolor = bgcolor
Expand All @@ -157,22 +153,19 @@ def before_update(self):
assert (
self.text or self.icon or (self.__content and self.__content.visible)
), "at minimum, text, icon or a visible content must be provided"
if any([self.__color, self.__bgcolor, self.__elevation]):
self.__style = self.__style or ButtonStyle()
if self.__style:
if self.__color is not None:
self.__style.color = self.__color

if self.__bgcolor is not None:
self.__style.bgcolor = self.__bgcolor

if self.__elevation is not None:
self.__style.elevation = self.__elevation
self.__style.side = self._wrap_attr_dict(self.__style.side)
self.__style.shape = self._wrap_attr_dict(self.__style.shape)
self.__style.padding = self._wrap_attr_dict(self.__style.padding)
self.__style.text_style = self._wrap_attr_dict(self.__style.text_style)
self._set_attr_json("style", self.__style)
style = self.__style or ButtonStyle()
if self.__color is not None:
style.color = self.__color
if self.__bgcolor is not None:
style.bgcolor = self.__bgcolor
if self.__elevation is not None:
style.elevation = self.__elevation

style.side = self._wrap_attr_dict(style.side)
style.shape = self._wrap_attr_dict(style.shape)
style.padding = self._wrap_attr_dict(style.padding)
style.text_style = self._wrap_attr_dict(style.text_style)
self._set_attr_json("style", style)

def _get_children(self):
if self.__content is None:
Expand Down