Skip to content

Commit 20ab93c

Browse files
committed
Filled elevated button
1 parent c1c814b commit 20ab93c

File tree

5 files changed

+113
-72
lines changed

5 files changed

+113
-72
lines changed

client/lib/controls/elevated_button.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ElevatedButtonControl extends StatelessWidget {
3030
HexColor.fromString(context, control.attrString("iconColor", "")!);
3131
var contentCtrls = children.where((c) => c.name == "content");
3232
bool autofocus = control.attrBool("autofocus", false)!;
33+
bool filled = control.attrBool("filled", false)!;
34+
bool filledTonal = control.attrBool("filledTonal", false)!;
3335
bool disabled = control.isDisabled || parentDisabled;
3436

3537
Function()? onPressed = disabled
@@ -43,9 +45,27 @@ class ElevatedButtonControl extends StatelessWidget {
4345
};
4446

4547
ElevatedButton? button;
48+
ButtonStyle? style;
49+
50+
if (filled) {
51+
style = ElevatedButton.styleFrom(
52+
// Foreground color
53+
onPrimary: Theme.of(context).colorScheme.onPrimary,
54+
// Background color
55+
primary: Theme.of(context).colorScheme.primary,
56+
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0));
57+
} else if (filledTonal) {
58+
style = ElevatedButton.styleFrom(
59+
// Foreground color
60+
onPrimary: Theme.of(context).colorScheme.onSecondaryContainer,
61+
// Background color
62+
primary: Theme.of(context).colorScheme.secondaryContainer,
63+
).copyWith(elevation: ButtonStyleButton.allOrNull(0.0));
64+
}
4665

4766
if (icon != null) {
4867
button = ElevatedButton.icon(
68+
style: style,
4969
autofocus: autofocus,
5070
onPressed: onPressed,
5171
icon: Icon(
@@ -55,11 +75,13 @@ class ElevatedButtonControl extends StatelessWidget {
5575
label: Text(text));
5676
} else if (contentCtrls.isNotEmpty) {
5777
button = ElevatedButton(
78+
style: style,
5879
autofocus: autofocus,
5980
onPressed: onPressed,
6081
child: createControl(control, contentCtrls.first.id, disabled));
6182
} else {
62-
button = ElevatedButton(onPressed: onPressed, child: Text(text));
83+
button =
84+
ElevatedButton(style: style, onPressed: onPressed, child: Text(text));
6385
}
6486

6587
return constrainedControl(button, parent, control);

client/lib/controls/page.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import '../models/app_state.dart';
77
import '../models/control.dart';
88
import '../models/control_children_view_model.dart';
99
import '../utils/alignment.dart';
10-
import '../utils/color_theme.dart';
1110
import '../utils/colors.dart';
1211
import '../utils/edge_insets.dart';
1312
import '../utils/theme.dart';
@@ -72,7 +71,7 @@ class PageControl extends StatelessWidget {
7271
// theme
7372
var theme = parseTheme(control, "theme") ??
7473
ThemeData(
75-
colorScheme: lightColorScheme,
74+
colorSchemeSeed: Colors.blue,
7675
brightness: Brightness.light,
7776
useMaterial3: true,
7877
// fontFamily: kIsWeb && window.navigator.userAgent.contains('OS 15_')
@@ -82,7 +81,7 @@ class PageControl extends StatelessWidget {
8281

8382
var darkTheme = parseTheme(control, "darkTheme") ??
8483
ThemeData(
85-
colorScheme: darkColorScheme,
84+
colorSchemeSeed: Colors.blue,
8685
brightness: Brightness.dark,
8786
useMaterial3: true,
8887
visualDensity: VisualDensity.adaptivePlatformDensity);

client/lib/utils/color_theme.dart

Lines changed: 0 additions & 67 deletions
This file was deleted.

sdk/python/flet/elevated_button.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __init__(
2323
#
2424
# Specific
2525
#
26+
filled: bool = None,
27+
filled_tonal: bool = None,
2628
icon: str = None,
2729
icon_color: str = None,
2830
content: Control = None,
@@ -43,6 +45,8 @@ def __init__(
4345
)
4446

4547
self.text = text
48+
self.filled = filled
49+
self.filled_tonal = filled_tonal
4650
self.icon = icon
4751
self.icon_color = icon_color
4852
self.content = content
@@ -67,6 +71,26 @@ def text(self):
6771
def text(self, value):
6872
self._set_attr("text", value)
6973

74+
# filled
75+
@property
76+
def filled(self):
77+
return self._get_attr("filled", data_type="bool", def_value=False)
78+
79+
@filled.setter
80+
@beartype
81+
def filled(self, value: Optional[bool]):
82+
self._set_attr("filled", value)
83+
84+
# filled_tonal
85+
@property
86+
def filled_tonal(self):
87+
return self._get_attr("filledTonal", data_type="bool", def_value=False)
88+
89+
@filled_tonal.setter
90+
@beartype
91+
def filled_tonal(self, value: Optional[bool]):
92+
self._set_attr("filledTonal", value)
93+
7094
# icon
7195
@property
7296
def icon(self):

sdk/python/playground/buttons.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def main(page: Page):
3232
expand=1,
3333
scroll=True,
3434
controls=[
35-
Text("Elevated buttons", style="headlineMedium"),
35+
Text("Elevated button", style="headlineMedium"),
3636
ElevatedButton("Normal button"),
3737
ElevatedButton("Disabled button", disabled=True),
3838
ElevatedButton(
@@ -56,6 +56,69 @@ def main(page: Page):
5656
alignment="spaceAround",
5757
),
5858
),
59+
#
60+
#
61+
#
62+
Text("Elevated Filled button", style="headlineMedium"),
63+
ElevatedButton("Filled button", filled=True),
64+
ElevatedButton("Disabled button", filled=True, disabled=True),
65+
ElevatedButton(
66+
"Button with icon and tooltip",
67+
filled=True,
68+
icon="chair_outlined",
69+
tooltip="Hey, click me!",
70+
),
71+
ElevatedButton(
72+
"Button with colorful icon",
73+
filled=True,
74+
icon="park_rounded",
75+
icon_color="green400",
76+
),
77+
ElevatedButton(
78+
width=150,
79+
filled=True,
80+
content=Row(
81+
[
82+
Icon(name="favorite", color="pink"),
83+
Icon(name="audiotrack", color="green"),
84+
Icon(name="beach_access", color="blue"),
85+
],
86+
alignment="spaceAround",
87+
),
88+
),
89+
#
90+
#
91+
#
92+
Text("Elevated Filled Tonal button", style="headlineMedium"),
93+
ElevatedButton("Tonal button", filled_tonal=True),
94+
ElevatedButton("Disabled button", filled_tonal=True, disabled=True),
95+
ElevatedButton(
96+
"Button with icon and tooltip",
97+
filled_tonal=True,
98+
icon="chair_outlined",
99+
tooltip="Hey, click me!",
100+
),
101+
ElevatedButton(
102+
"Button with colorful icon",
103+
filled_tonal=True,
104+
icon="park_rounded",
105+
icon_color="green400",
106+
),
107+
ElevatedButton(
108+
width=150,
109+
filled_tonal=True,
110+
content=Row(
111+
[
112+
Icon(name="favorite", color="pink"),
113+
Icon(name="audiotrack", color="green"),
114+
Icon(name="beach_access", color="blue"),
115+
],
116+
alignment="spaceAround",
117+
),
118+
),
119+
#
120+
#
121+
#
59122
Text("Outlined buttons", style="headlineMedium"),
60123
OutlinedButton("Normal button"),
61124
OutlinedButton("Disabled button", disabled=True),

0 commit comments

Comments
 (0)