我正在编写一个聊天应用程序,但是要实现降低加载更多数据的效果,我有一个问题。
我要达到效果:
摘要:
class _List3PageState extends State<List3Page> {
List<String> _stringList = [];
int i = 0;
@override
void initState() {
super.initState();
for (int i = 0; i < 5; i++) {
_stringList.add('chat data');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('pull down to load more data'),
),
body: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: _stringList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Text(_stringList[index]),
);
},
),
),
FlatButton(
onPressed: () {
List<String> oldData = [];
oldData.add('chat old data $i');
i += 1;
oldData.add('chat old data $i');
i += 1;
oldData.add('chat old data $i');
i += 1;
oldData.add('chat old data $i');
i += 1;
_stringList.insertAll(0, oldData);
setState(() {});
},
child: Text('load old chat data')),
],
),
);
}
}
答案 0 :(得分:0)
也许您可以用手势检测器包围列表视图,然后使用onVerticalDragDown事件。