赞
踩
本文介绍Flutter中的下拉刷新组件:
class RefreshIndicator extends StatefulWidget {
const RefreshIndicator({
Key? key,
required this.child,
this.displacement = 40.0,
required this.onRefresh,
this.color,
this.backgroundColor,
this.notificationPredicate = defaultScrollNotificationPredicate,
this.semanticsLabel,
this.semanticsValue,
this.strokeWidth = 2.0,
this.triggerMode = RefreshIndicatorTriggerMode.onEdge,
})
}
属性 | 说明 | 取值 |
---|---|---|
child | 显示的数据试图 | 通常是[ListView] or [CustomScrollView] |
displacement | 指示器到顶部或者底部到距离 | double |
color | 指示器的前置颜色 | Color |
backgroundColor | 指示器的背景颜色 | Color |
List<int> _list =[1, 2, 3,]; body: RefreshIndicator( color: Colors.red, backgroundColor: Colors.lightBlue, onRefresh: () { setState(() { _list.add(_list.length+1); }); return Future.delayed(Duration(seconds:1)); }, child: ListView.separated(itemCount: _list.length, separatorBuilder: (context,index){return Divider(height: 10,color: Colors.red,);} , itemBuilder: (BuildContext context, int index){ return Center(child: Text("数据${_list[index]}"),heightFactor: 1.5,); }, ), )
const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics())
,不设置无法下拉滚动List<int> _list =[1, 2, 3,]; CustomScrollView( physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), slivers: <Widget>[ //const CupertinoSliverNavigationBar(largeTitle: Text('Scroll down')), CupertinoSliverRefreshControl( refreshTriggerPullDistance: 100.0, refreshIndicatorExtent: 60.0, onRefresh: () async { await Future<void>.delayed(const Duration(milliseconds: 1000)); setState(() { _list.add(_list.length+1); }); }, ), SliverList(delegate: SliverChildBuilderDelegate((BuildContext context, int index) => Center(child: Column(children: [Text("数据${_list[index]}"), Divider(height: 10,color: Colors.red,)],),), childCount: _list.length,),), ], )
Github-flutter_easyrefresh:https://github.com/xuelongqy/flutter_easyrefresh
flutter_easyrefresh 2.2.1:https://pub.flutter-io.cn/packages/flutter_easyrefresh
打开CMD终端,执行如下指令(自动添加pubspec.yaml依赖)
flutter pub add flutter_easyrefresh
打开CMD终端,执行如下指令(pubspec.yaml依赖被删除)
flutter pub remove flutter_easyrefresh
List<int> _list =[1, 2, 3,];
EasyRefresh(
child: ListView.separated(itemCount: _list.length,
separatorBuilder: (context,index){return Divider(height: 10,color: Colors.red,);} ,
itemBuilder: (BuildContext context, int index){return Center(child: Text("数据${_list[index]}"),heightFactor: 1.5,);}, ),
onRefresh: () async{
await Future<void>.delayed(const Duration(milliseconds: 1000));
setState(() {_list.add(_list.length+1);});
},
onLoad: () async{
await Future<void>.delayed(const Duration(milliseconds: 1000));
setState(() {_list.remove(_list.length);});
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。