1
1
import time
2
- from typing import Any , Optional , Union
2
+ from typing import Any , Dict , Optional , Union
3
3
4
4
from flet_core .adaptive_control import AdaptiveControl
5
5
from flet_core .buttons import ButtonStyle
9
9
from flet_core .tooltip import TooltipValue
10
10
from flet_core .types import (
11
11
AnimationValue ,
12
+ ClipBehavior ,
13
+ ControlState ,
12
14
OffsetValue ,
15
+ OptionalControlEventCallable ,
13
16
ResponsiveNumber ,
14
17
RotateValue ,
15
18
ScaleValue ,
16
- ClipBehavior ,
17
19
UrlTarget ,
18
- OptionalControlEventCallable ,
19
20
)
20
21
from flet_core .utils import deprecated
21
22
@@ -48,10 +49,10 @@ def __init__(
48
49
text : Optional [str ] = None ,
49
50
icon : Optional [str ] = None ,
50
51
icon_color : Optional [str ] = None ,
51
- color : Optional [ str ] = None ,
52
- bgcolor : Optional [ str ] = None ,
52
+ color : Union [ None , str , Dict [ ControlState , str ] ] = None ,
53
+ bgcolor : Union [ None , str , Dict [ ControlState , str ] ] = None ,
53
54
content : Optional [Control ] = None ,
54
- elevation : OptionalNumber = None ,
55
+ elevation : Union [ OptionalNumber , Dict [ ControlState , OptionalNumber ]] = None ,
55
56
style : Optional [ButtonStyle ] = None ,
56
57
autofocus : Optional [bool ] = None ,
57
58
clip_behavior : Optional [ClipBehavior ] = None ,
@@ -127,10 +128,6 @@ def __init__(
127
128
128
129
AdaptiveControl .__init__ (self , adaptive = adaptive )
129
130
130
- self .__color = None
131
- self .__bgcolor = None
132
- self .__elevation = None
133
-
134
131
self .text = text
135
132
self .color = color
136
133
self .bgcolor = bgcolor
@@ -157,27 +154,18 @@ def before_update(self):
157
154
assert (
158
155
self .text or self .icon or (self .__content and self .__content .visible )
159
156
), "at minimum, text, icon or a visible content must be provided"
157
+ style = ButtonStyle ()
160
158
if any ([self .__color , self .__bgcolor , self .__elevation ]):
161
- self .__style = self .__style or ButtonStyle ()
162
- if self .__style :
163
- self .__style .color = (
164
- self .__style .color if self .__style .color is not None else self .color
165
- )
166
- self .__style .bgcolor = (
167
- self .__style .bgcolor
168
- if self .__style .bgcolor is not None
169
- else self .bgcolor
170
- )
171
- self .__style .elevation = (
172
- self .__style .elevation
173
- if self .__style .elevation is not None
174
- else self .elevation
175
- )
176
- self .__style .side = self ._wrap_attr_dict (self .__style .side )
177
- self .__style .shape = self ._wrap_attr_dict (self .__style .shape )
178
- self .__style .padding = self ._wrap_attr_dict (self .__style .padding )
179
- self .__style .text_style = self ._wrap_attr_dict (self .__style .text_style )
180
- self ._set_attr_json ("style" , self .__style )
159
+ style = self .__style or style
160
+ if style :
161
+ style .color = style .color or self .__color
162
+ style .bgcolor = style .bgcolor or self .__bgcolor
163
+ style .elevation = style .elevation or self .__elevation
164
+ style .side = self ._wrap_attr_dict (style .side )
165
+ style .shape = self ._wrap_attr_dict (style .shape )
166
+ style .padding = self ._wrap_attr_dict (style .padding )
167
+ style .text_style = self ._wrap_attr_dict (style .text_style )
168
+ self ._set_attr_json ("style" , style )
181
169
182
170
def _get_children (self ):
183
171
if self .__content is None :
@@ -208,30 +196,31 @@ def text(self, value: Optional[str]):
208
196
209
197
# color
210
198
@property
211
- def color (self ) -> Optional [ str ]:
199
+ def color (self ) -> Union [ None , str , Dict [ ControlState , str ] ]:
212
200
return self .__color
213
201
214
202
@color .setter
215
- def color (self , value : Optional [ str ]):
203
+ def color (self , value : Union [ None , str , Dict [ ControlState , str ] ]):
216
204
self .__color = value
217
205
218
206
# bgcolor
219
207
@property
220
- def bgcolor (self ) -> Optional [ str ]:
208
+ def bgcolor (self ) -> Union [ None , str , Dict [ ControlState , str ] ]:
221
209
return self .__bgcolor
222
210
223
211
@bgcolor .setter
224
- def bgcolor (self , value : Optional [ str ]):
212
+ def bgcolor (self , value : Union [ None , str , Dict [ ControlState , str ] ]):
225
213
self .__bgcolor = value
226
- self ._set_attr ("bgColor" , value )
227
214
228
215
# elevation
229
216
@property
230
- def elevation (self ) -> OptionalNumber :
217
+ def elevation (self ) -> Union [ OptionalNumber , Dict [ ControlState , OptionalNumber ]] :
231
218
return self .__elevation
232
219
233
220
@elevation .setter
234
- def elevation (self , value : OptionalNumber ):
221
+ def elevation (
222
+ self , value : Union [OptionalNumber , Dict [ControlState , OptionalNumber ]]
223
+ ):
235
224
self .__elevation = value
236
225
237
226
# style
0 commit comments