2024-01-25 17:40:41 +08:00
|
|
|
import 'package:easy_refresh/easy_refresh.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 下拉刷新封装
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* child 显示组件
|
|
|
|
|
* onRefresh 上拉刷新
|
|
|
|
|
* onLoad 下拉刷新
|
|
|
|
|
* isMore 是否存在分页
|
|
|
|
|
* page 页数
|
|
|
|
|
*
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalKey<_EasyRefreshToolState> childKey = GlobalKey();
|
|
|
|
|
|
|
|
|
|
class EasyRefreshTool extends StatefulWidget {
|
|
|
|
|
Widget child;
|
|
|
|
|
Function? onRefresh;
|
|
|
|
|
Function? onLoad;
|
|
|
|
|
late int isMore;
|
|
|
|
|
late int page;
|
|
|
|
|
|
|
|
|
|
EasyRefreshTool({Key? key,required this.child,this.onRefresh,this.onLoad,this.isMore=0,this.page=0}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<EasyRefreshTool> createState() => _EasyRefreshToolState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _EasyRefreshToolState extends State<EasyRefreshTool> {
|
|
|
|
|
late EasyRefreshController _controller;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_controller = EasyRefreshController();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return EasyRefresh(
|
|
|
|
|
controller: _controller,
|
|
|
|
|
header: const MaterialHeader(),
|
|
|
|
|
footer: const MaterialFooter(),
|
2024-03-19 18:04:51 +08:00
|
|
|
triggerAxis: Axis.vertical,
|
2024-01-25 17:40:41 +08:00
|
|
|
onRefresh: widget.onRefresh!=null?() async {
|
|
|
|
|
if(widget.onRefresh != null){
|
|
|
|
|
widget.onRefresh!();
|
|
|
|
|
}
|
|
|
|
|
}:null,
|
|
|
|
|
onLoad: widget.onLoad!=null?() async {
|
|
|
|
|
|
|
|
|
|
// if(widget.isMore>0){
|
|
|
|
|
widget.onLoad!();
|
|
|
|
|
// }
|
|
|
|
|
}:null,
|
|
|
|
|
child: widget.child,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|