Skip to content

Commit cc3b29e

Browse files
wrap ListTile in material widget (#4206)
1 parent 3057155 commit cc3b29e

File tree

1 file changed

+125
-123
lines changed

1 file changed

+125
-123
lines changed

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

Lines changed: 125 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -51,130 +51,132 @@ class ListTileControl extends StatelessWidget with FletStoreMixin {
5151
@override
5252
Widget build(BuildContext context) {
5353
debugPrint("ListTile build: ${control.id}");
54-
return withPagePlatform((context, platform) {
55-
bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive;
56-
if (adaptive == true &&
57-
(platform == TargetPlatform.iOS ||
58-
platform == TargetPlatform.macOS)) {
59-
return CupertinoListTileControl(
60-
control: control,
61-
parent: parent,
62-
parentDisabled: parentDisabled,
63-
parentAdaptive: adaptive,
64-
children: children,
65-
backend: backend);
66-
}
67-
68-
var leadingCtrls =
69-
children.where((c) => c.name == "leading" && c.isVisible);
70-
var titleCtrls = children.where((c) => c.name == "title" && c.isVisible);
71-
var subtitleCtrls =
72-
children.where((c) => c.name == "subtitle" && c.isVisible);
73-
var trailingCtrls =
74-
children.where((c) => c.name == "trailing" && c.isVisible);
75-
76-
var titleAlignment =
77-
parseListTileTitleAlignment(control.attrString("titleAlignment"));
78-
var style = parseListTileStyle(control.attrString("style"));
79-
80-
bool selected = control.attrBool("selected", false)!;
81-
bool dense = control.attrBool("dense", false)!;
82-
bool isThreeLine = control.attrBool("isThreeLine", false)!;
83-
bool autofocus = control.attrBool("autofocus", false)!;
84-
bool onclick = control.attrBool("onclick", false)!;
85-
bool toggleInputs = control.attrBool("toggleInputs", false)!;
86-
bool onLongPressDefined = control.attrBool("onLongPress", false)!;
87-
bool? enableFeedback = control.attrBool("enableFeedback");
88-
double? horizontalSpacing = control.attrDouble("horizontalSpacing");
89-
double? minLeadingWidth = control.attrDouble("minLeadingWidth");
90-
double? minVerticalPadding = control.attrDouble("minVerticalPadding");
91-
String url = control.attrString("url", "")!;
92-
String? urlTarget = control.attrString("urlTarget");
93-
bool disabled = control.isDisabled || parentDisabled;
94-
95-
Function()? onPressed =
96-
(onclick || toggleInputs || url != "") && !disabled
97-
? () {
98-
debugPrint("ListTile ${control.id} clicked!");
99-
if (toggleInputs) {
100-
_clickNotifier.onClick();
54+
return Material(
55+
child: withPagePlatform((context, platform) {
56+
bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive;
57+
if (adaptive == true &&
58+
(platform == TargetPlatform.iOS ||
59+
platform == TargetPlatform.macOS)) {
60+
return CupertinoListTileControl(
61+
control: control,
62+
parent: parent,
63+
parentDisabled: parentDisabled,
64+
parentAdaptive: adaptive,
65+
children: children,
66+
backend: backend);
67+
}
68+
69+
var leadingCtrls =
70+
children.where((c) => c.name == "leading" && c.isVisible);
71+
var titleCtrls = children.where((c) => c.name == "title" && c.isVisible);
72+
var subtitleCtrls =
73+
children.where((c) => c.name == "subtitle" && c.isVisible);
74+
var trailingCtrls =
75+
children.where((c) => c.name == "trailing" && c.isVisible);
76+
77+
var titleAlignment =
78+
parseListTileTitleAlignment(control.attrString("titleAlignment"));
79+
var style = parseListTileStyle(control.attrString("style"));
80+
81+
bool selected = control.attrBool("selected", false)!;
82+
bool dense = control.attrBool("dense", false)!;
83+
bool isThreeLine = control.attrBool("isThreeLine", false)!;
84+
bool autofocus = control.attrBool("autofocus", false)!;
85+
bool onclick = control.attrBool("onclick", false)!;
86+
bool toggleInputs = control.attrBool("toggleInputs", false)!;
87+
bool onLongPressDefined = control.attrBool("onLongPress", false)!;
88+
bool? enableFeedback = control.attrBool("enableFeedback");
89+
double? horizontalSpacing = control.attrDouble("horizontalSpacing");
90+
double? minLeadingWidth = control.attrDouble("minLeadingWidth");
91+
double? minVerticalPadding = control.attrDouble("minVerticalPadding");
92+
String url = control.attrString("url", "")!;
93+
String? urlTarget = control.attrString("urlTarget");
94+
bool disabled = control.isDisabled || parentDisabled;
95+
96+
Function()? onPressed =
97+
(onclick || toggleInputs || url != "") && !disabled
98+
? () {
99+
debugPrint("ListTile ${control.id} clicked!");
100+
if (toggleInputs) {
101+
_clickNotifier.onClick();
102+
}
103+
if (url != "") {
104+
openWebBrowser(url, webWindowName: urlTarget);
105+
}
106+
if (onclick) {
107+
backend.triggerControlEvent(control.id, "click");
108+
}
101109
}
102-
if (url != "") {
103-
openWebBrowser(url, webWindowName: urlTarget);
104-
}
105-
if (onclick) {
106-
backend.triggerControlEvent(control.id, "click");
107-
}
108-
}
109-
: null;
110-
111-
Function()? onLongPress = onLongPressDefined && !disabled
112-
? () {
113-
debugPrint("Button ${control.id} clicked!");
114-
backend.triggerControlEvent(control.id, "long_press");
115-
}
116-
: null;
117-
118-
Widget tile = ListTile(
119-
autofocus: autofocus,
120-
contentPadding: parseEdgeInsets(control, "contentPadding"),
121-
isThreeLine: isThreeLine,
122-
selected: selected,
123-
dense: dense,
124-
onTap: onPressed,
125-
onLongPress: onLongPress,
126-
enabled: !disabled,
127-
horizontalTitleGap: horizontalSpacing,
128-
enableFeedback: enableFeedback,
129-
minLeadingWidth: minLeadingWidth,
130-
minVerticalPadding: minVerticalPadding,
131-
minTileHeight: control.attrDouble("minHeight"),
132-
selectedTileColor: control.attrColor("selectedTileColor", context),
133-
selectedColor: control.attrColor("selectedColor", context),
134-
focusColor: control.attrColor("focusColor", context),
135-
tileColor: control.attrColor("bgcolor", context),
136-
splashColor: control.attrColor("bgcolorActivated", context),
137-
hoverColor: control.attrColor("hoverColor", context),
138-
iconColor: control.attrColor("iconColor", context),
139-
textColor: control.attrColor("textColor", context),
140-
mouseCursor: parseMouseCursor(control.attrString("mouseCursor")),
141-
visualDensity: parseVisualDensity(control.attrString("visualDensity")),
142-
shape: parseOutlinedBorder(control, "shape"),
143-
titleTextStyle:
144-
parseTextStyle(Theme.of(context), control, "titleTextStyle"),
145-
leadingAndTrailingTextStyle: parseTextStyle(
146-
Theme.of(context), control, "leadingAndTrailingTextStyle"),
147-
subtitleTextStyle:
148-
parseTextStyle(Theme.of(context), control, "subtitleTextStyle"),
149-
titleAlignment: titleAlignment,
150-
style: style,
151-
onFocusChange: (bool hasFocus) {
152-
backend.triggerControlEvent(control.id, hasFocus ? "focus" : "blur");
153-
},
154-
leading: leadingCtrls.isNotEmpty
155-
? createControl(control, leadingCtrls.first.id, disabled,
156-
parentAdaptive: adaptive)
157-
: null,
158-
title: titleCtrls.isNotEmpty
159-
? createControl(control, titleCtrls.first.id, disabled,
160-
parentAdaptive: adaptive)
161-
: null,
162-
subtitle: subtitleCtrls.isNotEmpty
163-
? createControl(control, subtitleCtrls.first.id, disabled,
164-
parentAdaptive: adaptive)
165-
: null,
166-
trailing: trailingCtrls.isNotEmpty
167-
? createControl(control, trailingCtrls.first.id, disabled,
168-
parentAdaptive: adaptive)
169-
: null,
170-
);
171-
172-
if (toggleInputs) {
173-
tile = ListTileClicks(notifier: _clickNotifier, child: tile);
174-
}
175-
176-
return constrainedControl(context, tile, parent, control);
177-
});
110+
: null;
111+
112+
Function()? onLongPress = onLongPressDefined && !disabled
113+
? () {
114+
debugPrint("Button ${control.id} clicked!");
115+
backend.triggerControlEvent(control.id, "long_press");
116+
}
117+
: null;
118+
119+
Widget tile = ListTile(
120+
autofocus: autofocus,
121+
contentPadding: parseEdgeInsets(control, "contentPadding"),
122+
isThreeLine: isThreeLine,
123+
selected: selected,
124+
dense: dense,
125+
onTap: onPressed,
126+
onLongPress: onLongPress,
127+
enabled: !disabled,
128+
horizontalTitleGap: horizontalSpacing,
129+
enableFeedback: enableFeedback,
130+
minLeadingWidth: minLeadingWidth,
131+
minVerticalPadding: minVerticalPadding,
132+
minTileHeight: control.attrDouble("minHeight"),
133+
selectedTileColor: control.attrColor("selectedTileColor", context),
134+
selectedColor: control.attrColor("selectedColor", context),
135+
focusColor: control.attrColor("focusColor", context),
136+
tileColor: control.attrColor("bgcolor", context),
137+
splashColor: control.attrColor("bgcolorActivated", context),
138+
hoverColor: control.attrColor("hoverColor", context),
139+
iconColor: control.attrColor("iconColor", context),
140+
textColor: control.attrColor("textColor", context),
141+
mouseCursor: parseMouseCursor(control.attrString("mouseCursor")),
142+
visualDensity: parseVisualDensity(control.attrString("visualDensity")),
143+
shape: parseOutlinedBorder(control, "shape"),
144+
titleTextStyle:
145+
parseTextStyle(Theme.of(context), control, "titleTextStyle"),
146+
leadingAndTrailingTextStyle: parseTextStyle(
147+
Theme.of(context), control, "leadingAndTrailingTextStyle"),
148+
subtitleTextStyle:
149+
parseTextStyle(Theme.of(context), control, "subtitleTextStyle"),
150+
titleAlignment: titleAlignment,
151+
style: style,
152+
onFocusChange: (bool hasFocus) {
153+
backend.triggerControlEvent(control.id, hasFocus ? "focus" : "blur");
154+
},
155+
leading: leadingCtrls.isNotEmpty
156+
? createControl(control, leadingCtrls.first.id, disabled,
157+
parentAdaptive: adaptive)
158+
: null,
159+
title: titleCtrls.isNotEmpty
160+
? createControl(control, titleCtrls.first.id, disabled,
161+
parentAdaptive: adaptive)
162+
: null,
163+
subtitle: subtitleCtrls.isNotEmpty
164+
? createControl(control, subtitleCtrls.first.id, disabled,
165+
parentAdaptive: adaptive)
166+
: null,
167+
trailing: trailingCtrls.isNotEmpty
168+
? createControl(control, trailingCtrls.first.id, disabled,
169+
parentAdaptive: adaptive)
170+
: null,
171+
);
172+
173+
if (toggleInputs) {
174+
tile = ListTileClicks(notifier: _clickNotifier, child: tile);
175+
}
176+
177+
return constrainedControl(context, tile, parent, control);
178+
}));
179+
178180
}
179181
}
180182

0 commit comments

Comments
 (0)