Skip to content

Commit

Permalink
Fix MaterialState error in ButtonStyle (#689)
Browse files Browse the repository at this point in the history
* Fix MaterialState error in ButtonStyle

Fix #685

* Fix ButtonStyle typings
  • Loading branch information
FeodorFitsner authored Dec 8, 2022
1 parent 95e006d commit d669577
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
28 changes: 19 additions & 9 deletions sdk/python/flet/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,29 @@ class CountinuosRectangleBorder(OutlinedBorder):

@dataclasses.dataclass
class ButtonStyle:
color: Union[None, str, Dict[MaterialState, str]] = field(default=None)
bgcolor: Union[None, str, Dict[MaterialState, str]] = field(default=None)
overlay_color: Union[None, str, Dict[MaterialState, str]] = field(default=None)
shadow_color: Union[None, str, Dict[MaterialState, str]] = field(default=None)
surface_tint_color: Union[None, str, Dict[MaterialState, str]] = field(default=None)
elevation: Union[None, float, int, Dict[MaterialState, Union[float, int]]] = field(
color: Union[None, str, Dict[Union[str, MaterialState], str]] = field(default=None)
bgcolor: Union[None, str, Dict[Union[str, MaterialState], str]] = field(
default=None
)
overlay_color: Union[None, str, Dict[Union[str, MaterialState], str]] = field(
default=None
)
shadow_color: Union[None, str, Dict[Union[str, MaterialState], str]] = field(
default=None
)
surface_tint_color: Union[None, str, Dict[Union[str, MaterialState], str]] = field(
default=None
)
elevation: Union[
None, float, int, Dict[Union[str, MaterialState], Union[float, int]]
] = field(default=None)
animation_duration: Optional[int] = field(default=None)
padding: Union[PaddingValue, Dict[MaterialState, PaddingValue]] = field(
padding: Union[PaddingValue, Dict[Union[str, MaterialState], PaddingValue]] = field(
default=None
)
side: Union[None, BorderSide, Dict[MaterialState, BorderSide]] = field(default=None)
shape: Union[None, OutlinedBorder, Dict[MaterialState, OutlinedBorder]] = field(
side: Union[None, BorderSide, Dict[Union[str, MaterialState], BorderSide]] = field(
default=None
)
shape: Union[
None, OutlinedBorder, Dict[Union[str, MaterialState], OutlinedBorder]
] = field(default=None)
7 changes: 5 additions & 2 deletions sdk/python/flet/embed_json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ def default(self, obj):
}
elif isinstance(obj, ButtonStyle):
for k, v in obj.__dict__.items():
if v is not None and not isinstance(v, Dict):
obj.__dict__[k] = {"": v}
if v is not None:
if not isinstance(v, Dict):
obj.__dict__[k] = {"": v}
if k != "animation_duration":
obj.__dict__[k] = self._cleanup_dict(obj.__dict__[k])
return self._cleanup_dict(obj.__dict__)
elif isinstance(obj, object):
return self._cleanup_dict(obj.__dict__)
Expand Down

0 comments on commit d669577

Please sign in to comment.