//https://github.com/xuelongqy/flutter_easyrefresh
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_easyrefresh/easy_refresh.dart';
/// 基本使用页面
class BasicPageextends StatefulWidget {
@override
_BasicPageState createState() => _BasicPageState();
}
class _BasicPageStateextends State {
ListaddStr = ["1","2","3","4","5","6","7","8","9","10"];
Liststr = ["A","B","C","D","E","F","G","H","I","J"];
GlobalKey_easyRefreshKey = GlobalKey();
GlobalKey_headerKey = GlobalKey();
GlobalKey_footerKey = GlobalKey();
bool_loadMore =true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("basicUse"),
),
body: Center(
child:new EasyRefresh(
key:_easyRefreshKey,
behavior: ScrollOverBehavior(),
refreshHeader: ClassicsHeader(
key:_headerKey,
refreshText:"pullToRefresh",
refreshReadyText:"releaseToRefresh",
refreshingText:"refreshing" +"...",
refreshedText:"refreshed",
moreInfo:"updateAt",
bgColor: Colors.transparent,
textColor: Colors.black87,
moreInfoColor: Colors.black54,
showMore:true,
),
refreshFooter: ClassicsFooter(
key:_footerKey,
loadText:"pushToLoad",
loadReadyText:"releaseToLoad",
loadingText:"loading",
loadedText:"loaded",
noMoreText:"noMore",
moreInfo:"updateAt",
bgColor: Colors.transparent,
textColor: Colors.black87,
moreInfoColor: Colors.black54,
showMore:true,
),
child:new ListView.builder(
//ListView的Item
itemCount:str.length,
itemBuilder: (BuildContext context, int index) {
return new Container(
height:70.0,
child: Card(
child:new Center(
child:new Text(
str[index],
style:new TextStyle(fontSize:18.0),
),
),
));
}),
onRefresh: ()async {
await new Future.delayed(const Duration(seconds:1), () {
setState(() {
str.clear();
str.addAll(addStr);
_easyRefreshKey.currentState.waitState(() {
setState(() {
_loadMore =true;
});
});
});
});
},
loadMore:_loadMore
? ()async {
await new Future.delayed(const Duration(seconds:1), () {
if (str.length <20) {
setState(() {
str.addAll(addStr);
});
}else {
_easyRefreshKey.currentState.waitState(() {
setState(() {
_loadMore =false;
});
});
}
});
}
:null,
)),
persistentFooterButtons: [
FlatButton(
onPressed: () {
_easyRefreshKey.currentState.callRefresh();
},
child: Text("refresh",
style: TextStyle(color: Colors.black))),
FlatButton(
onPressed: () {
_easyRefreshKey.currentState.callLoadMore();
},
child: Text("loadMore",
style: TextStyle(color: Colors.black)))
],// This trailing comma makes auto-formatting nicer for build methods.
);
}
}