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 createState() => _EasyRefreshToolState(); } class _EasyRefreshToolState extends State { 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(), triggerAxis: Axis.vertical, 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, ); } }