Skip to content

Commit 218f5ca

Browse files
committed
bgColor for ImageButton
1 parent 21c95c7 commit 218f5ca

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

client/lib/controls/icon_button.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class IconButtonControl extends StatelessWidget {
2828
IconData? icon = getMaterialIcon(control.attrString("icon", "")!);
2929
Color? iconColor =
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
31+
Color? bgColor =
32+
HexColor.fromString(context, control.attrString("bgColor", "")!);
3133
double? iconSize = control.attrDouble("iconSize");
3234
var contentCtrls = children.where((c) => c.name == "content");
3335
bool autofocus = control.attrBool("autofocus", false)!;
@@ -43,7 +45,7 @@ class IconButtonControl extends StatelessWidget {
4345
eventData: control.attrs["data"] ?? "");
4446
};
4547

46-
IconButton? button;
48+
Widget? button;
4749

4850
if (icon != null) {
4951
button = IconButton(
@@ -65,6 +67,14 @@ class IconButtonControl extends StatelessWidget {
6567
"Icon button does not have an icon neither content specified.");
6668
}
6769

70+
if (bgColor != null) {
71+
button = Container(
72+
decoration:
73+
ShapeDecoration(color: bgColor, shape: const CircleBorder()),
74+
child: button,
75+
);
76+
}
77+
6878
return constrainedControl(button, parent, control);
6979
}
7080
}

docs/roadmap.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ Properties:
741741

742742
- icon
743743
- iconColor
744+
- bgcolor
744745
- iconSize
745746
- tooltip
746747
- content - a Control representing custom button content

sdk/python/flet/icon_button.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def __init__(
2525
#
2626
icon_size: OptionalNumber = None,
2727
icon_color: str = None,
28+
bgcolor: str = None,
2829
content: Control = None,
2930
autofocus: bool = None,
3031
on_click=None,
@@ -45,6 +46,7 @@ def __init__(
4546
self.icon = icon
4647
self.icon_size = icon_size
4748
self.icon_color = icon_color
49+
self.bgcolor = bgcolor
4850
self.content = content
4951
self.autofocus = autofocus
5052
self.on_click = on_click
@@ -85,6 +87,15 @@ def icon_color(self):
8587
def icon_color(self, value):
8688
self._set_attr("iconColor", value)
8789

90+
# bgcolor
91+
@property
92+
def bgcolor(self):
93+
return self._get_attr("bgcolor")
94+
95+
@bgcolor.setter
96+
def bgcolor(self, value):
97+
self._set_attr("bgcolor", value)
98+
8899
# on_click
89100
@property
90101
def on_click(self):

sdk/python/playground/avatar-test.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import flet
2-
from flet import CircleAvatar, Icon, Text, colors, icons
2+
from flet import CircleAvatar, Icon, Stack, Text, alignment, colors, icons
3+
from flet.container import Container
34

45

56
def main(page):
@@ -23,7 +24,21 @@ def main(page):
2324
color=colors.YELLOW_200,
2425
bgcolor=colors.AMBER_700,
2526
)
26-
page.add(a1, a2, a3, a4)
27+
# avatar with online status
28+
a5 = Stack(
29+
[
30+
CircleAvatar(
31+
foreground_image_url="https://avatars.githubusercontent.com/u/5041459?s=88&v=4"
32+
),
33+
Container(
34+
content=CircleAvatar(bgcolor=colors.GREEN, radius=5),
35+
alignment=alignment.bottom_left,
36+
),
37+
],
38+
width=40,
39+
height=40,
40+
)
41+
page.add(a1, a2, a3, a4, a5)
2742

2843

2944
flet.app(target=main)

sdk/python/playground/buttons.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from flet import (
77
Column,
88
ElevatedButton,
9+
FloatingActionButton,
910
Icon,
1011
IconButton,
1112
OutlinedButton,
1213
Page,
1314
Row,
1415
Text,
1516
TextButton,
17+
icons,
1618
)
1719

1820
logging.basicConfig(level=logging.DEBUG)
@@ -105,6 +107,12 @@ def main(page: Page):
105107
icon_color="pink600",
106108
tooltip="Delete record",
107109
),
110+
IconButton(
111+
icon=icons.ANDROID,
112+
icon_color="white",
113+
bgcolor="blue",
114+
tooltip="Beep... Beep... Beep...",
115+
),
108116
]
109117
),
110118
],

0 commit comments

Comments
 (0)