1、使用方法 布局
SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: true,
header: HeaderWidget(),
footer: FooterWidget(),
onRefresh: _onRefresh,
onLoading: _onLoad,
child:widget)
2、记得释放
@override
void dispose() {
// TODO: implement dispose
_refreshController.dispose();
super.dispose();
3、初始化
RefreshController _refreshController =
RefreshController(initialRefresh: false);
4、获取数据 以及操作逻辑
void getData() {
///获取数据
Map<String, dynamic> params = {};
selectCourseResponsitory
.getHigherUpsListData(courseType, majorId, sMajorId, start, (p0) {
if (start == 0) {
_refreshController.refreshCompleted();
dataSource.clear();
} else {
if (p0.isEmpty) {
_refreshController.loadNoData();
} else {
_refreshController.loadComplete();
start = (start + 1) * 10;
///10是limit
dataSource.addAll(p0);
setState(() {});
(p0) => {
print(p0),
_refreshController.loadFailed(),
setState(() {})
5、下拉刷新(修改start 即可 逻辑在第四步)
/// 下拉刷新方法
// ignore: missing_return
Future<dynamic> _onRefresh() {
start = 0;
getData();
6、加载逻辑(只调用即可 逻辑在第四步)
///上拉加载
Future<dynamic> _onLoad() {
getData();
自定义header和footer
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
//用于下拉刷新 头布局
class HeaderWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return WaterDropHeader(
refresh: CircularProgressIndicator(),
complete: Text("刷新完成"),
idleIcon: new CircularProgressIndicator(),
waterDropColor: null,
//用于上拉加载 底部布局
class FooterWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CustomFooter(
builder: (BuildContext context, LoadStatus mode) {
Widget body;
if (mode == LoadStatus.idle) {
body = Text("上拉加载");
} else if (mode == LoadStatus.loading) {
body = CupertinoActivityIndicator();
} else if (mode == LoadStatus.failed) {
body = Text("加载失败");
} else if (mode == LoadStatus.canLoading) {
body = Text("松开加载更多");
} else if(mode == LoadStatus.noMore){
body = Text("没有更多数据");
}else{
// body = Text("没有更多数据");
body = Text("");
return Container(
height: 55.0,
child: Center(child: body),