Commit 82e751f9 authored by jinzhu's avatar jinzhu

完成 上拉下拉刷新页面

parent 321694ab
...@@ -17,33 +17,34 @@ class _MessageHomePageState extends State<MessageHomePage> { ...@@ -17,33 +17,34 @@ class _MessageHomePageState extends State<MessageHomePage> {
List<ListItem> messageList = List<ListItem>(); List<ListItem> messageList = List<ListItem>();
List<ListItem> dataArr = List<ListItem>(); List<ListItem> dataArr = List<ListItem>();
int pageIndex = 1; int pageIndex = 1;
List<String> data1 = [];
RefreshController _refreshController = RefreshController _refreshController =
RefreshController(initialRefresh: true); RefreshController(initialRefresh: true);
void _onRefresh() async{ void _onRefresh() async{
// dataArr = await _fetchListData(); pageIndex = 1;
// if (mounted) setState(() { List<ListItem> newdataArr = List<ListItem>();
// dataArr = dataArr; newdataArr = await _fetchListData();
// }); if (mounted) setState(() {
// _refreshController.refreshCompleted(); dataArr = newdataArr;
});
_refreshController.refreshCompleted();
} }
void _onLoading() async{ void _onLoading() async{
// monitor network fetch pageIndex ++;
// pageIndex ++; List<ListItem> newData = List<ListItem>();
// List<ListItem> newData = List<ListItem>(); newData = await _fetchMesssageList();
// newData = await _fetchMesssageList(); if (mounted) setState(() {
// this.dataArr.addAll(newData); this.dataArr.addAll(newData);
// if (mounted) setState(() { });
// dataArr = dataArr; _refreshController.loadComplete();
// });
// _refreshController.loadComplete();
} }
Future<List<ListItem>> _fetchMesssageList() async { Future<List<ListItem>> _fetchMesssageList() async {
List<Message> messageList = List<Message>(); List<Message> messageList = List<Message>();
BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': 1, 'count': 10}); BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': pageIndex, 'count': 10});
if (baseresp.code != 0) { if (baseresp.code != 0) {
return new Future.error(baseresp.msg); return new Future.error(baseresp.msg);
} }
...@@ -99,59 +100,31 @@ class _MessageHomePageState extends State<MessageHomePage> { ...@@ -99,59 +100,31 @@ class _MessageHomePageState extends State<MessageHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
// appBar: new AppBar( appBar: new AppBar(
// title: new Text('消息'), title: new Text('消息'),
// ), ),
// floatingActionButton: new FloatingActionButton( body: new Container(
// onPressed: () { child: SmartRefresher(
// _fetchListData(); child: _createListView(),
// },
// child: new Icon(Icons.add_box),
// elevation: 3.0,
// highlightElevation: 2.0,
// backgroundColor: Colors.red, // 红色
// ),
body: new Container(
child: SmartRefresher(
// enablePullDown: false,
enablePullUp: true,
// header: WaterDropHeader(),
controller: _refreshController, controller: _refreshController,
// onRefresh: _onRefresh, enablePullDown: true,
onLoading: _onLoading, enablePullUp: true,
header: WaterDropHeader(),
// footer: ClassicFooter(), onRefresh: (){
child: FutureBuilder( _onRefresh();
future: _fetchListData(), },
builder: (context, snapshot) { onLoading: () {
switch (snapshot.connectionState) { _onLoading();
case ConnectionState.none: }
return new Container(height:0.0,width:0.0); ),
break; )
case ConnectionState.waiting:
return new Container(height:0.0,width:0.0);
break;
case ConnectionState.active:
return new Container(height:0.0,width:0.0);
break;
default:
if (snapshot.hasData) {
return _createListView(context, snapshot);
} else {
return new Container(height:0.0,width:0.0);
}
}
},
),
),
)
); );
} }
Widget _createListView(BuildContext context, AsyncSnapshot snapshot) { Widget _createListView() {
List<ListItem> dataArr = snapshot.data; List<ListItem> dataArr = this.dataArr;
return ListView.builder( return ListView.builder(
shrinkWrap: true, shrinkWrap: true,
key: new PageStorageKey('message-list'), key: new PageStorageKey('message-list'),
...@@ -168,5 +141,4 @@ class _MessageHomePageState extends State<MessageHomePage> { ...@@ -168,5 +141,4 @@ class _MessageHomePageState extends State<MessageHomePage> {
}, },
); );
} }
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment