@@ -10,6 +10,7 @@ import 'package:flutter_picgo/views/album_page/album_page_presenter.dart';
1010import 'package:permission_handler/permission_handler.dart' ;
1111import 'package:toast/toast.dart' ;
1212import 'package:flutter/services.dart' ;
13+ import 'package:pull_to_refresh/pull_to_refresh.dart' ;
1314
1415class AlbumPage extends StatefulWidget {
1516 @override
@@ -19,6 +20,10 @@ class AlbumPage extends StatefulWidget {
1920class _AlbumPageState extends State <AlbumPage > implements AlbumPageContract {
2021 AlbumPagePresenter _presenter;
2122 List <Uploaded > _uploadeds = [];
23+ RefreshController _refreshController =
24+ RefreshController (initialRefresh: false );
25+ int _perPageItemSize = 8 ;
26+ int _currentPage = 0 ;
2227
2328 _AlbumPageState () {
2429 _presenter = AlbumPagePresenter (this );
@@ -27,7 +32,7 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
2732 @override
2833 void initState () {
2934 super .initState ();
30- _presenter. doLoadUploadedImages ();
35+ _onRefresh ();
3136 }
3237
3338 @override
@@ -49,8 +54,44 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
4954 transition: TransitionType .cupertino);
5055 },
5156 ),
52- body: RefreshIndicator (
57+ body: SmartRefresher (
58+ enablePullDown: true ,
59+ enablePullUp: this ._uploadeds.length >= _perPageItemSize,
60+ header: ClassicHeader (
61+ refreshStyle: RefreshStyle .Follow ,
62+ idleText: '下拉刷新' ,
63+ releaseText: '释放刷新' ,
64+ completeText: '加载完成' ,
65+ refreshingText: '刷新中' ,
66+ failedText: '加载失败,请重试' ,
67+ ),
68+ footer: CustomFooter (
69+ builder: (BuildContext context, LoadStatus mode) {
70+ Widget body;
71+ if (mode == LoadStatus .idle) {
72+ body = Text ("上拉加载" );
73+ } else if (mode == LoadStatus .loading) {
74+ body = SizedBox (
75+ width: 15 ,
76+ height: 15 ,
77+ child: CircularProgressIndicator (),
78+ );
79+ } else if (mode == LoadStatus .failed) {
80+ body = Text ("加载失败!点击重试!" );
81+ } else if (mode == LoadStatus .canLoading) {
82+ body = Text ("松手,加载更多!" );
83+ } else {
84+ body = Text ("没有更多数据了!" );
85+ }
86+ return Container (
87+ height: 55.0 ,
88+ child: Center (child: body),
89+ );
90+ },
91+ ),
5392 onRefresh: _onRefresh,
93+ onLoading: _onLoading,
94+ controller: _refreshController,
5495 child: _uploadeds.length > 0 ? albumView () : emptyView ()),
5596 );
5697 }
@@ -142,35 +183,44 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
142183 }
143184
144185 Widget emptyView () {
145- return ListView (
146- children : < Widget > [
147- SizedBox (height : 100 ) ,
148- Center (
149- child : Container (
186+ return Center (
187+ child : Column (
188+ mainAxisAlignment : MainAxisAlignment .center ,
189+ children : < Widget > [
190+ Container (
150191 width: 200 ,
151192 height: 200 ,
152193 child: Image .asset ('assets/images/icon_empty_album.png' ,
153194 fit: BoxFit .fill),
154195 ),
155- ),
156- SizedBox (height: 10 ),
157- Center (
158- child: Text (
159- '相册暂无任何照片,快点击右下角按钮去上传吧' ,
160- style: TextStyle (color: Colors .grey),
161- ),
162- )
163- ],
196+ Center (
197+ child: Text (
198+ '相册暂无任何照片,快点击右下角按钮去上传吧' ,
199+ style: TextStyle (color: Colors .grey),
200+ ),
201+ )
202+ ],
203+ ),
164204 );
165205 }
166206
167- Future <dynamic > _onRefresh () async {
207+ /// 刷新
208+ _onRefresh () async {
209+ // _uploadeds.clear();
168210 setState (() {
169- _uploadeds.clear ();
211+ this ._currentPage = 0 ;
212+ this ._uploadeds.clear ();
213+ _refreshController.resetNoData ();
170214 });
171- return _presenter.doLoadUploadedImages ();
215+ _presenter.doLoadUploadedImages (_perPageItemSize, this ._currentPage);
216+ }
217+
218+ /// 上拉加载
219+ _onLoading () async {
220+ _presenter.doLoadUploadedImages (_perPageItemSize, _currentPage += 1 );
172221 }
173222
223+ /// 处理图片点击
174224 handleTap (int index) {
175225 Clipboard .setData (ClipboardData (text: _uploadeds[index].path));
176226 Toast .show ('已复制到剪切板' , context);
@@ -179,13 +229,29 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
179229 @override
180230 void loadUploadedImages (List <Uploaded > uploadeds) {
181231 setState (() {
182- this ._uploadeds.addAll (uploadeds);
232+ if (this ._currentPage == 0 ) {
233+ _refreshController.refreshCompleted ();
234+ } else if (this ._currentPage > 0 &&
235+ (uploadeds == null || uploadeds.length == 0 )) {
236+ _refreshController.loadNoData ();
237+ } else {
238+ this ._currentPage += 1 ;
239+ _refreshController.loadComplete ();
240+ }
241+ if (uploadeds != null && uploadeds.length > 0 ) {
242+ this ._uploadeds.addAll (uploadeds);
243+ }
183244 });
184245 }
185246
186247 @override
187248 void loadError () {
188249 Toast .show ('加载失败' , context);
250+ if (this ._currentPage == 1 ) {
251+ _refreshController.refreshFailed ();
252+ } else {
253+ _refreshController.loadFailed ();
254+ }
189255 }
190256
191257 @override
0 commit comments