Android中实现列表的方式有ListView、GrildView、ExpandableListView,后边出来另一个非常好用的RecyclerView,那么今天我们就看看flutter如何实现列表显示的。
import 'package:flutter/material.dart';
//数据源
final Set<Person> sets = new Set<Person>();
void main() {
runApp(new MaterialApp(
title: 'flutter 示例',
home: new ListViewWidget()
));
}
class ListViewWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new ListViewState();
}
}
class ListViewState extends State<ListViewWidget> {
List<ItemWidget> list = new List<ItemWidget>();
add() {
print('回调了add()');
setState(() {
sets.add(new Person('战士 ${sets.length + 1}', '我是第${sets.length + 1}个兵'));
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(