listview概述
ListView
无论是在Android
(兼容了android中的ScrollView
和ListView
,可以当列表也可以充当滑动布局)和IOS
开发中,使用的频率都是很高的,而且功能也是很强大。在Flutter
中也不例外,也是一个非常常用的布局方式之一,在Flutter
中ListView
结合ListTile
可以布局出一些复杂的列表界面。
ListView列表item-ListTile构造函数
构造函数如下
const ListTile({
Key key,
this.leading,//item的图标
this.title,//item标题
this.subtitle,//item的副标题
this.trailing,//item的后置图标
this.isThreeLine = false,//item是否三行显示
this.dense,//item直观整体的大小
this.contentPadding,//item的内容内边距
this.enabled = true,
this.onTap,//item ontap的点击事件
this.onLongPress,//item长按事件
this.selected = false,//item是否选中状态
})
ListView示例代码
import 'package:flutter/material.dart';
void main(){
runApp(new MaterialApp(
title: 'ListView布局示例',
home: new MyApp(),
));
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
List<Widget> list =<Widget>[
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路3号'),
leading: new Icon(
Icons.fastfood,
color: Colors.orange,
),
isThreeLine: true,
enabled: true,
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路7号'),
leading: new Icon(
Icons.airplay,
color: Colors.blue,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路3号'),
leading: new Icon(
Icons.local_hospital,
color: Colors.yellow,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路18号'),
leading: new Icon(
Icons.computer,
color: Colors.green,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.face,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.fast_forward,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.fast_rewind,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.favorite,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.favorite_border,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.dashboard,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.airplay,
color: Colors.grey,
),
),
new ListTile(
title: new Text(
'北京市海淀区甘家口街道办事处',
style: new TextStyle(
fontWeight: FontWeight.w400,fontSize: 18.0,),),
subtitle: new Text('广州市福黄埔大道建中路21号'),
leading: new Icon(
Icons.battery_full,
color: Colors.grey,
),
),
];
return new Scaffold(
appBar: new AppBar(
title: new Text('ListView示例布局'),
),
body: new ListView(
children: list,
),
);
}
}
priontString(){
print('这是listView的点击打印');
}