在Application中写入:
分别写getHeader() 和getFooter() 方法来获取头部和尾部
class Application{
static Widget getHeader(_headerKey) {
return ClassicsHeader(
key: _headerKey,
refreshText: '下拉刷新',
refreshReadyText: '准备刷新',
refreshingText: '刷新中...',
refreshedText: '刷新完成',
moreInfo: '更新于 %T',
bgColor: Colors.transparent,
textColor: Colors.black87,
moreInfoColor: Colors.black54,
showMore: true,
);
}
static Widget getFooter(_footerKey) {
return ClassicsFooter(
key: _footerKey,
loadText: '上拉加载',
loadReadyText: '准备加载',
loadingText: '加载中...',
loadedText: '加载完成',
noMoreText: '没有更多',
moreInfo: '更新于 %T',
bgColor: Colors.transparent,
textColor: Colors.black87,
moreInfoColor: Colors.black54,
showMore: true,
);
}
}
使用:
定义变量key,然后添加头部时加入key值
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import '../../application.dart';
class FirstPage extends StatefulWidget {
@override
_FirstPageState createState() => _FirstPageState();
}
class _FirstPageState extends State<FirstPage> {
GlobalKey<RefreshHeaderState> _headerKey = GlobalKey<RefreshHeaderState>();
GlobalKey<RefreshFooterState> _footerKey = GlobalKey<RefreshFooterState>();
GlobalKey<EasyRefreshState> _key = new GlobalKey<EasyRefreshState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: _title(),
actions: <Widget>[_actions()],
),
body: EasyRefresh(
refreshHeader: Application.getHeader(_headerKey),
refreshFooter: Application.getFooter(_footerKey),
key: _key,
onRefresh: () async {
},
loadMore: () async {
},
child: ListView(
shrinkWrap: true,
children: <Widget>[
],
)),
);
}
}