话不多说先上图片
然后我们先上代码后说实现
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class SmartRefresherBuild extends StatefulWidget {
/// 子级展示数据
final Widget child;
/// 总条数
final int total;
/// 当前条数
final int length;
/// 上拉事件
final Function upActive;
/// 下拉事件
final Function downActive;
const SmartRefresherBuild(
{super.key,
required this.child,
required this.total,
required this.length,
required this.upActive,
required this.downActive});
@override
State<SmartRefresherBuild> createState() => _SmartRefresherBuildState();
}
class _SmartRefresherBuildState extends State<SmartRefresherBuild> {
final RefreshController _refreshController =
RefreshController(initialRefresh: false);
void _onRefrech() async {
await Future.delayed(const Duration(microseconds: 1000));
widget.downActive();
_refreshController.refreshCompleted();
}
void _onLoading() async {
await Future.delayed(const Duration(milliseconds: 1000));
widget.upActive();
if (mounted) setState(() {});
_refreshController.loadComplete();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SmartRefresher(
enablePullDown: true,
enablePullUp: widget.length < widget.total,
header: const WaterDropHeader(),
controller: _refreshController,
onRefresh: _onRefrech,
onLoading: _onLoading,
child: widget.child),
);
}
}
这里呢我们需要传入我们列表模块的Widget child,我的列表总长度,当前的列表长度, 以及我们的上拉下拉所对应的 事件
纯小白 大佬勿怪 !!!
纯小白 大佬勿怪 !!!
纯小白 大佬勿怪 !!!