Skip to content

Commit afc67a5

Browse files
committed
ListTile
1 parent 03548c5 commit afc67a5

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

client/lib/controls/create_control.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'card.dart';
2+
import 'list_tile.dart';
23
import 'navigation_rail.dart';
34

45
import 'package:flutter/material.dart';
@@ -161,6 +162,12 @@ Widget createControl(Control? parent, String id, bool parentDisabled) {
161162
control: controlView.control,
162163
children: controlView.children,
163164
parentDisabled: parentDisabled);
165+
case ControlType.listTile:
166+
return ListTileControl(
167+
parent: parent,
168+
control: controlView.control,
169+
children: controlView.children,
170+
parentDisabled: parentDisabled);
164171
case ControlType.listView:
165172
return ListViewControl(
166173
parent: parent,

client/lib/controls/list_tile.dart

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'package:flutter/material.dart';
2+
3+
import '../models/control.dart';
4+
import '../utils/edge_insets.dart';
5+
import '../web_socket_client.dart';
6+
import 'create_control.dart';
7+
8+
class ListTileControl extends StatelessWidget {
9+
final Control? parent;
10+
final Control control;
11+
final List<Control> children;
12+
final bool parentDisabled;
13+
14+
const ListTileControl(
15+
{Key? key,
16+
this.parent,
17+
required this.control,
18+
required this.children,
19+
required this.parentDisabled})
20+
: super(key: key);
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
debugPrint("ListTile build: ${control.id}");
25+
26+
var leadingCtrls =
27+
children.where((c) => c.name == "leading" && c.isVisible);
28+
var titleCtrls = children.where((c) => c.name == "title" && c.isVisible);
29+
var subtitleCtrls =
30+
children.where((c) => c.name == "subtitle" && c.isVisible);
31+
var trailingCtrls =
32+
children.where((c) => c.name == "trailing" && c.isVisible);
33+
34+
bool selected = control.attrBool("selected", false)!;
35+
bool dense = control.attrBool("dense", false)!;
36+
bool isThreeLine = control.attrBool("isThreeLine", false)!;
37+
bool autofocus = control.attrBool("autofocus", false)!;
38+
bool disabled = control.isDisabled || parentDisabled;
39+
40+
Function()? onPressed = disabled
41+
? null
42+
: () {
43+
debugPrint("ListTile ${control.id} clicked!");
44+
ws.pageEventFromWeb(
45+
eventTarget: control.id,
46+
eventName: "click",
47+
eventData: control.attrs["data"] ?? "");
48+
};
49+
50+
ListTile tile = ListTile(
51+
autofocus: autofocus,
52+
contentPadding: parseEdgeInsets(control, "contentPadding"),
53+
isThreeLine: isThreeLine,
54+
selected: selected,
55+
dense: dense,
56+
onTap: onPressed,
57+
leading: leadingCtrls.isNotEmpty
58+
? createControl(control, leadingCtrls.first.id, disabled)
59+
: null,
60+
title: titleCtrls.isNotEmpty
61+
? createControl(control, titleCtrls.first.id, disabled)
62+
: null,
63+
subtitle: subtitleCtrls.isNotEmpty
64+
? createControl(control, subtitleCtrls.first.id, disabled)
65+
: null,
66+
trailing: trailingCtrls.isNotEmpty
67+
? createControl(control, trailingCtrls.first.id, disabled)
68+
: null,
69+
);
70+
71+
return constrainedControl(tile, parent, control);
72+
}
73+
}

sdk/python/flet/list_tile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(
3131
trailing: Control = None,
3232
is_three_line: bool = None,
3333
selected: bool = None,
34+
dense: bool = None,
3435
autofocus: bool = None,
3536
on_click=None,
3637
):
@@ -54,6 +55,7 @@ def __init__(
5455
self.trailing = trailing
5556
self.is_three_line = is_three_line
5657
self.selected = selected
58+
self.dense = dense
5759
self.autofocus = autofocus
5860
self.on_click = on_click
5961

@@ -149,6 +151,16 @@ def selected(self):
149151
def selected(self, value: Optional[bool]):
150152
self._set_attr("selected", value)
151153

154+
# dense
155+
@property
156+
def dense(self):
157+
return self._get_attr("dense", data_type="bool", def_value=False)
158+
159+
@dense.setter
160+
@beartype
161+
def dense(self, value: Optional[bool]):
162+
self._set_attr("dense", value)
163+
152164
# autofocus
153165
@property
154166
def autofocus(self):
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import logging
2+
3+
import flet
4+
from flet import (
5+
Card,
6+
Column,
7+
Container,
8+
Icon,
9+
Image,
10+
ListTile,
11+
PopupMenuButton,
12+
PopupMenuItem,
13+
Text,
14+
icons,
15+
padding,
16+
)
17+
18+
logging.basicConfig(level=logging.DEBUG)
19+
20+
21+
def main(page):
22+
page.title = "ListTile Examples"
23+
# page.theme_mode = "dark"
24+
page.add(
25+
Card(
26+
content=Container(
27+
width=500,
28+
content=Column(
29+
[
30+
ListTile(
31+
title=Text("One-line list tile"),
32+
),
33+
ListTile(title=Text("One-line dense list tile"), dense=True),
34+
ListTile(
35+
leading=Icon(icons.SETTINGS),
36+
title=Text("One-line selected list tile"),
37+
selected=True,
38+
),
39+
ListTile(
40+
leading=Image(src="/icons/icon-192.png", fit="contain"),
41+
title=Text("One-line with leading control"),
42+
),
43+
ListTile(
44+
title=Text("One-line with trailing control"),
45+
trailing=PopupMenuButton(
46+
icon=icons.MORE_VERT,
47+
items=[
48+
PopupMenuItem(text="Item 1"),
49+
PopupMenuItem(text="Item 2"),
50+
],
51+
),
52+
),
53+
ListTile(
54+
leading=Icon(icons.ALBUM),
55+
title=Text("One-line with leading and trailing controls"),
56+
trailing=PopupMenuButton(
57+
icon=icons.MORE_VERT,
58+
items=[
59+
PopupMenuItem(text="Item 1"),
60+
PopupMenuItem(text="Item 2"),
61+
],
62+
),
63+
),
64+
ListTile(
65+
leading=Icon(icons.SNOOZE),
66+
title=Text("Two-line with leading and trailing controls"),
67+
subtitle=Text("Here is a second title."),
68+
trailing=PopupMenuButton(
69+
icon=icons.MORE_VERT,
70+
items=[
71+
PopupMenuItem(text="Item 1"),
72+
PopupMenuItem(text="Item 2"),
73+
],
74+
),
75+
),
76+
],
77+
spacing=0,
78+
),
79+
padding=padding.symmetric(vertical=10),
80+
)
81+
)
82+
)
83+
84+
85+
flet.app(name="test1", port=8550, target=main, view=flet.WEB_BROWSER)

0 commit comments

Comments
 (0)