@@ -6,6 +6,23 @@ class Index extends StatefulWidget {
66}
77
88class _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}
0 commit comments