Skip to content

Commit 43bfe2a

Browse files
samsam
authored andcommitted
feat:ListTile
1 parent 4485c72 commit 43bfe2a

File tree

3 files changed

+105
-5
lines changed

3 files changed

+105
-5
lines changed
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
## **文档完善中**
1+
## **ListTile**
2+
>
3+
单个固定高度的行,通常包含一些文本和前导或者尾随的图标,通常在ListView中使用
4+
5+
### 构造方法
6+
``` dart
7+
ListTile({
8+
Key key,
9+
this.leading,
10+
this.title,
11+
this.subtitle,
12+
this.trailing,
13+
this.isThreeLine = false,
14+
this.dense,
15+
this.contentPadding,
16+
this.enabled = true,
17+
this.onTap,
18+
this.onLongPress,
19+
this.selected = false,
20+
})
21+
```
22+
23+
### 属性介绍
24+
25+
* leading:显示左侧的小组件
26+
* title:标题
27+
* subtitle:子标题
28+
* trailing:显示右侧的小组件
29+
* isThreeLine = false:是否显示三行文本
30+
* dense:是否垂直密集显示
31+
* contentPadding:ListTile的内部填充
32+
* enabled = true:是否是交互式的
33+
* onTap:点击时的回调
34+
* onLongPress:长按时的回调
35+
* selected = false:图标和文本是否以相同颜色呈现

lib/widget/common/listtile/demo.dart

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ class Index extends StatefulWidget {
66
}
77

88
class _IndexState extends State<Index> {
9+
List data = [
10+
{
11+
'enable': true,
12+
'subtitle': 'subtitle is not focus',
13+
'selected': false
14+
},
15+
{
16+
'enable': false,
17+
'subtitle': 'subtitle is not focus',
18+
'selected': true
19+
},
20+
{
21+
'enable': true,
22+
'subtitle': 'subtitle is not focus',
23+
'selected': true
24+
}
25+
];
926
@override
1027
void initState() {
1128
super.initState();
@@ -17,9 +34,58 @@ class _IndexState extends State<Index> {
1734
appBar: AppBar(
1835
title: Text('ListTile'),
1936
),
20-
body: Center(
21-
child: Text('更新中'),
22-
),
37+
body: Container(
38+
padding: EdgeInsets.fromLTRB(20.0, 0, 20.0, 0),
39+
child: ListView.builder(
40+
itemCount: data.length,
41+
itemBuilder: (context, index) {
42+
return Column(
43+
children: <Widget>[
44+
ListTile(
45+
leading: CircleAvatar(
46+
backgroundImage: AssetImage('assets/imgs/cool.jpg'),
47+
),
48+
title: Text('title'),
49+
subtitle: Text(data[index]['subtitle']),
50+
trailing: Icon(Icons.arrow_right),
51+
onTap: (){
52+
if (!data[index]['selected']) {
53+
this.setState((){
54+
data[index]['subtitle'] = 'subtitle is focus now';
55+
data[index]['selected'] = true;
56+
});
57+
} else {
58+
this.setState((){
59+
data[index]['subtitle'] = 'subtitle is not focus';
60+
data[index]['selected'] = false;
61+
});
62+
}
63+
},
64+
onLongPress: (){
65+
Scaffold.of(context).showSnackBar(
66+
SnackBar(
67+
content: Text('你长按了我'),
68+
backgroundColor: Theme.of(context).primaryColor,
69+
action: SnackBarAction(
70+
textColor: Colors.white,
71+
label: '取消',
72+
onPressed: (){},
73+
),
74+
duration: Duration(seconds: 2),
75+
)
76+
);
77+
},
78+
selected: data[index]['selected'],
79+
isThreeLine: false,
80+
enabled: data[index]['enable'],
81+
contentPadding: EdgeInsets.all(0),
82+
),
83+
Divider()
84+
],
85+
);
86+
},
87+
)
88+
)
2389
);
2490
}
2591
}

readme/widget_progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Flutter UI
5656
│ ├─icon 【✔️ v1.0】
5757
│ ├─iconbutton
5858
│ ├─image 【✔️ v1.0】
59-
│ ├─listtile
59+
│ ├─listtile 【✔️ v1.0】
6060
│ ├─placeholder
6161
│ ├─raisedbutton
6262
│ ├─rawimage

0 commit comments

Comments
 (0)