Flutter ListView 上拉滑动加载更多
//ListView滚动Demo import 'dart:ffi'; import 'package:flutter/material.dart'; void main() { runApp(DemoApp()); } class DemoApp extends StatefulWidget { @override State<StatefulWidget> createState() { return new DemoAppState(); } } class DemoAppState extends State { //初始化 var _items = []; int countIndex = 0; @override void dispose() { super.dispose(); } @override void initState() { super.initState(); getData(); } void getData() { //初始化数据源 for (int i = 0; i < 20; i++) { _items.insert(_items.length, "第${_items.length}条原始数据"); print(_items[i]); } } Future<void> _onRefresh() async { await Future.delayed(Duration(seconds: 1)).then((e) { setState(() { _items.clear(); for (int i = 0; i < 20; i++) { _items.insert(_items.length, "第${_items.length}条下拉刷新后的数据"); } }); }); } @override Widget build(BuildContext context) { return MaterialApp( title: 'SingleChildListViewDemo', home: Scaffold( appBar: AppBar( title: Text('SingleChildListViewDemo'), ), body: new ListView.separated( physics: BouncingScrollPhysics(), //ListView构造器 itemBuilder: (context, index) { return ListTile( title: Text( '$_items[$index]', textAlign: TextAlign.center, style: TextStyle(fontSize: 28.0, color: Colors.black38), ), ); }, separatorBuilder: (context, index) { return new Divider( color: Colors.blue, ); }, itemCount: _items.length, ), ), ); } }
![](https://img2022.cnblogs.com/blog/830732/202207/830732-20220719175616681-1569698304.png)