美文网首页
Flutter 基础控件之 ListView 可滑动列表

Flutter 基础控件之 ListView 可滑动列表

作者: 繁华乱世沧桑了谁的容颜 | 来源:发表于2020-08-21 10:27 被阅读0次
class _ListsListViewPageState extends       State<ListsListViewPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
    appBar: AppBar(
      title: Text('ListsListView'),
    ),
    body: MyListPage(
        items: new List<String>.generate(1000, (index) => 'Item $index')));
}
}

class MyListPage extends StatelessWidget {
final List<String> items;
MyListPage({Key key, @required this.items}) : super(key: key);

@override
Widget build(BuildContext context) {
return ListView.builder(
  itemCount: items.length,
  itemBuilder: (context, index) {
    return new ListTile(
      title: new Text('${items[index]}'),
    );
  },
);
}
}

效果如下


image.png

属性解析

1. itemCount 预设 列表的个数
1.itemBuilder 列表的布局widget

实际开发中使用该控件频率较高

相关文章

网友评论

      本文标题:Flutter 基础控件之 ListView 可滑动列表

      本文链接:https://www.haomeiwen.com/subject/hpksjktx.html