Commit 1f6adc8e authored by xuehao's avatar xuehao

listView新增下拉刷新,上拉加载,bug修复

parent 1dcb6ffa
...@@ -40,11 +40,11 @@ class _ListPageState extends State<List_Page> { ...@@ -40,11 +40,11 @@ class _ListPageState extends State<List_Page> {
itemBuilder: _getDatas, itemBuilder: _getDatas,
), ),
onRefresh: () async { onRefresh: () async {
setState(() { refreshData();
refreshData(); },
}); onLoad: () async {
loadData();
}, },
onLoad: () async {},
), ),
)); ));
} }
...@@ -76,15 +76,32 @@ class _ListPageState extends State<List_Page> { ...@@ -76,15 +76,32 @@ class _ListPageState extends State<List_Page> {
}, },
)); ));
} }
}
Future<void> refreshData() async { Future<void> refreshData() async {
await Future.delayed(Duration(seconds: 3), () { await Future.delayed(Duration(seconds: 3), () {
for (int i = 0; i < datas.length; i++) { setState(() {
datas[i].name = "刷新后的数据$i"; for (int i = 0; i < datas.length; i++) {
} datas[i].name = "刷新后的数据$i";
_controller.finishRefresh(success: true); }
}); _controller.finishRefresh(success: true);
});
});
}
///加载数据
Future<void> loadData() async {
await Future.delayed(Duration(seconds: 3), () {
setState(() {
for (int i = 0; i < 10; i++) {
datas.add(Car(
name: "新增数据$i",
imageUrl:
"https://img2.baidu.com/it/u=2010980676,2375641500&fm=11&fmt=auto&gp=0.jpg"));
}
_controller.finishLoad(success: true);
});
});
}
} }
//定义一个全局的变量:模型数组 //定义一个全局的变量:模型数组
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment