Flutter封装EasyRefresh的header,footer

在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>[
            ],
          )),
    );
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值