Skip to content

Commit dd9fcdf

Browse files
authored
Preparing v0.22.0 (#2992)
* _set_enum_attr * fix checked PopupMenuButton * random_color() * Cleanup rive.dart * Accept null in HexColor.fromString * Fix _set_enum_attr
1 parent 5d017e6 commit dd9fcdf

29 files changed

+55
-168
lines changed

packages/flet/lib/src/controls/popup_menu_button.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ class PopupMenuButtonControl extends StatelessWidget with FletStoreMixin {
128128
mouseCursor: parseMouseCursor(
129129
cv.control.attrString("mouseCursor")),
130130
onTap: () {
131-
backend.triggerControlEvent(cv.control.id, "click");
131+
backend.updateControlState(
132+
cv.control.id, {"checked": "${!checked}"});
133+
backend.triggerControlEvent(
134+
cv.control.id, "click", "${!checked}");
132135
},
133136
child: child,
134137
)

packages/flet/lib/src/utils/colors.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ Map<String, MaterialAccentColor> _materialAccentColors = {
137137

138138
// https://stackoverflow.com/questions/50081213/how-do-i-use-hexadecimal-color-strings-in-flutter
139139
extension HexColor on Color {
140-
static Color? fromString(ThemeData? theme, [String colorString = ""]) {
140+
static Color? fromString(ThemeData? theme, [String? colorString = ""]) {
141+
if (colorString == null || colorString.isEmpty) {
142+
return null;
143+
}
141144
var colorParts = colorString.split(",");
142145

143146
var colorValue = colorParts[0];
@@ -245,5 +248,5 @@ MaterialStateProperty<Color?>? parseMaterialStateColor(
245248

246249
final j1 = json.decode(v);
247250
return getMaterialStateProperty<Color?>(
248-
j1, (jv) => HexColor.fromString(theme, jv as String));
251+
j1, (jv) => HexColor.fromString(theme, jv as String), null);
249252
}

packages/flet_rive/lib/src/rive.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class _RiveControlState extends State<RiveControl> with FletStoreMixin {
4545
placeholder = createControl(widget.control, ctrls.first.id, disabled);
4646
}
4747

48-
void _onInit(artboard) {
49-
widget.backend.triggerControlEvent(widget.control.id, "init");
50-
}
51-
5248
return withPageArgs((context, pageArgs) {
5349
Widget? rive;
5450

@@ -63,7 +59,6 @@ class _RiveControlState extends State<RiveControl> with FletStoreMixin {
6359
useArtboardSize: useArtBoardSize,
6460
alignment: alignment,
6561
placeHolder: placeholder,
66-
// onInit: _onInit,
6762
);
6863
} else {
6964
// URL

sdk/python/packages/flet-core/src/flet_core/animated_switcher.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,4 @@ def transition(self) -> Optional[AnimatedSwitcherTransition]:
225225
@transition.setter
226226
def transition(self, value: Optional[AnimatedSwitcherTransition]):
227227
self.__transition = value
228-
self._set_attr(
229-
"transition",
230-
value.value if isinstance(value, AnimatedSwitcherTransition) else value,
231-
)
228+
self._set_enum_attr("transition", value, AnimatedSwitcherTransition)

sdk/python/packages/flet-core/src/flet_core/animation.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,13 @@
11
import dataclasses
22
from dataclasses import field
3-
from typing import Optional
43
from enum import Enum
4+
from typing import Optional
55

66
try:
77
from typing import Literal
88
except ImportError:
99
from typing_extensions import Literal
1010

11-
AnimationCurveString = Literal[
12-
"bounceIn",
13-
"bounceInOut",
14-
"bounceOut",
15-
"decelerate",
16-
"ease",
17-
"easeIn",
18-
"easeInBack",
19-
"easeInCirc",
20-
"easeInCubic",
21-
"easeInExpo",
22-
"easeInOut",
23-
"easeInOutBack",
24-
"easeInOutCirc",
25-
"easeInOutCubic",
26-
"easeInOutCubicEmphasized",
27-
"easeInOutExpo",
28-
"easeInOutQuad",
29-
"easeInOutQuart",
30-
"easeInOutQuint",
31-
"easeInOutSine",
32-
"easeInQuad",
33-
"easeInQuart",
34-
"easeInQuint",
35-
"easeInSine",
36-
"easeInToLinear",
37-
"easeOut",
38-
"easeOutBack",
39-
"easeOutCirc",
40-
"easeOutCubic",
41-
"easeOutExpo",
42-
"easeOutQuad",
43-
"easeOutQuart",
44-
"easeOutQuint",
45-
"easeOutSine",
46-
"elasticIn",
47-
"elasticInOut",
48-
"elasticOut",
49-
"fastLinearToSlowEaseIn",
50-
"fastOutSlowIn",
51-
"linear",
52-
"linearToEaseOut",
53-
"slowMiddle",
54-
]
55-
5611

5712
class AnimationCurve(Enum):
5813
BOUNCE_IN = "bounceIn"

sdk/python/packages/flet-core/src/flet_core/audio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ def release_mode(self):
237237

238238
@release_mode.setter
239239
def release_mode(self, value: Optional[ReleaseMode]):
240-
self._set_attr(
241-
"releaseMode", value.value if isinstance(value, ReleaseMode) else value
242-
)
240+
self._set_enum_attr("releaseMode", value, ReleaseMode)
243241

244242
# on_loaded
245243
@property

sdk/python/packages/flet-core/src/flet_core/audio_recorder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ def audio_encoder(self):
215215

216216
@audio_encoder.setter
217217
def audio_encoder(self, value: Optional[AudioEncoder]):
218-
self._set_attr(
219-
"audioEncoder", value.value if isinstance(value, AudioEncoder) else value
220-
)
218+
self._set_enum_attr("audioEncoder", value, AudioEncoder)
221219

222220
# suppress_noise
223221
@property

sdk/python/packages/flet-core/src/flet_core/card.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,4 @@ def variant(self) -> Optional[CardVariant]:
275275
@variant.setter
276276
def variant(self, value: Optional[CardVariant]):
277277
self.__variant = value
278-
self._set_attr(
279-
"variant", value.value if isinstance(value, CardVariant) else value
280-
)
278+
self._set_enum_attr("variant", value, CardVariant)

sdk/python/packages/flet-core/src/flet_core/colors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535
}
3636
"""
37+
import random
3738

3839

3940
def with_opacity(opacity: float, color: str):
@@ -377,3 +378,10 @@ def with_opacity(opacity: float, color: str):
377378
GREY_700 = "grey700"
378379
GREY_800 = "grey800"
379380
GREY_900 = "grey900"
381+
382+
colors_list = [v for k, v in vars().items() if k.isupper()]
383+
384+
385+
def random_color() -> str:
386+
"""Return a random color from the colors defined in this module."""
387+
return random.choice(colors_list)

sdk/python/packages/flet-core/src/flet_core/control.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import datetime as dt
22
import json
33
from difflib import SequenceMatcher
4-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
4+
from enum import Enum
5+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, Type
56

67
from flet_core.embed_json_encoder import EmbedJsonEncoder
78
from flet_core.protocol import Command
@@ -105,6 +106,11 @@ def _get_attr(self, name, def_value=None, data_type="string"):
105106
def _set_attr(self, name, value, dirty=True):
106107
self._set_attr_internal(name, value, dirty)
107108

109+
def _set_enum_attr(self, name, value, enum_type: Type[Enum], dirty=True):
110+
self._set_attr_internal(
111+
name, value.value if isinstance(value, enum_type) else value, dirty
112+
)
113+
108114
def _get_value_or_list_attr(self, name, delimiter):
109115
v = self._get_attr(name)
110116
if v and delimiter in v:

0 commit comments

Comments
 (0)