Skip to content

Commit

Permalink
dropdown.Option.text_style property (flet-dev#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndonkoHenri authored and zrr1999 committed Jul 17, 2024
1 parent 56852a8 commit 910bd34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/flet/lib/src/controls/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,22 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
.map((v) => v.control)
.where((c) => c.name == null && c.isVisible)
.map<DropdownMenuItem<String>>((Control itemCtrl) {
bool itemDisabled = disabled || itemCtrl.isDisabled;
TextStyle? textStyle =
parseTextStyle(Theme.of(context), itemCtrl, "textStyle");
if (itemDisabled && textStyle != null) {
textStyle = textStyle.apply(color: Theme.of(context).disabledColor);
}
Widget itemChild = Text(
itemCtrl.attrs["text"] ?? itemCtrl.attrs["key"] ?? itemCtrl.id,
style: textStyle,
);
var align = parseAlignment(itemCtrl, "alignment");
if (align != null) {
itemChild = Container(alignment: align, child: itemChild);
}
return DropdownMenuItem<String>(
enabled: !(disabled || itemCtrl.isDisabled),
enabled: !itemDisabled,
value: itemCtrl.attrs["key"] ?? itemCtrl.attrs["text"] ?? itemCtrl.id,
alignment: align ?? AlignmentDirectional.centerStart,
onTap: !(disabled || itemCtrl.isDisabled)
Expand Down
13 changes: 13 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
key: Optional[str] = None,
text: Optional[str] = None,
alignment: Optional[Alignment] = None,
text_style: Optional[TextStyle] = None,
on_click=None,
#
# Control
Expand All @@ -39,13 +40,16 @@ def __init__(
self.text = text
self.on_click = on_click
self.alignment = alignment
self.text_style = text_style

def _get_control_name(self):
return "dropdownoption"

def before_update(self):
super().before_update()
self._set_attr_json("alignment", self.__alignment)
if isinstance(self.__text_style, TextStyle):
self._set_attr_json("textStyle", self.__text_style)

# key
@property
Expand Down Expand Up @@ -74,6 +78,15 @@ def alignment(self) -> Optional[Alignment]:
def alignment(self, value: Optional[Alignment]):
self.__alignment = value

# text_style
@property
def text_style(self) -> Optional[TextStyle]:
return self.__text_style

@text_style.setter
def text_style(self, value: Optional[TextStyle]):
self.__text_style = value

# on_click
@property
def on_click(self):
Expand Down

0 comments on commit 910bd34

Please sign in to comment.