@@ -27,9 +27,12 @@ class GSYPullLoadWidget extends StatefulWidget {
2727}
2828
2929class _GSYPullLoadWidgetState extends State <GSYPullLoadWidget > {
30-
3130 final ScrollController _scrollController = new ScrollController ();
3231
32+ bool isRefreshing = false ;
33+
34+ bool isLoadMoring = false ;
35+
3336 @override
3437 void initState () {
3538 ///增加滑动监听
@@ -43,6 +46,14 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
4346 });
4447 widget.control.addListener (() {
4548 setState (() {});
49+ try {
50+ Future .delayed (Duration (seconds: 2 ), () {
51+ // ignore: invalid_use_of_visible_for_testing_member, invalid_use_of_protected_member
52+ _scrollController.notifyListeners ();
53+ });
54+ } catch (e) {
55+ print (e);
56+ }
4657 });
4758 super .initState ();
4859 }
@@ -84,24 +95,53 @@ class _GSYPullLoadWidgetState extends State<GSYPullLoadWidget> {
8495 }
8596 }
8697
98+ _lockToAwait () async {
99+ ///if loading, lock to await
100+ doDelayed () async {
101+ await Future .delayed (Duration (seconds: 1 )).then ((_) async {
102+ if (widget.control.isLoading) {
103+ return await doDelayed ();
104+ } else {
105+ return null ;
106+ }
107+ });
108+ }
109+
110+ await doDelayed ();
111+ }
112+
87113 @protected
88114 Future <Null > handleRefresh () async {
89115 if (widget.control.isLoading) {
90- return null ;
116+ if (isRefreshing) {
117+ return null ;
118+ }
119+
120+ ///if loading, lock to await
121+ await _lockToAwait ();
91122 }
92123 widget.control.isLoading = true ;
124+ isRefreshing = true ;
93125 await widget.onRefresh? .call ();
126+ isRefreshing = false ;
94127 widget.control.isLoading = false ;
95128 return null ;
96129 }
97130
98131 @protected
99132 Future <Null > handleLoadMore () async {
100133 if (widget.control.isLoading) {
101- return null ;
134+ if (isLoadMoring) {
135+ return null ;
136+ }
137+
138+ ///if loading, lock to await
139+ await _lockToAwait ();
102140 }
141+ isLoadMoring = true ;
103142 widget.control.isLoading = true ;
104143 await widget.onLoadMore? .call ();
144+ isLoadMoring = false ;
105145 widget.control.isLoading = false ;
106146 return null ;
107147 }
@@ -192,14 +232,14 @@ class GSYPullLoadWidgetControl extends ChangeNotifier {
192232
193233 set dataList (List value) {
194234 _dataList.clear ();
195- if (value != null ) {
235+ if (value != null ) {
196236 _dataList.addAll (value);
197237 notifyListeners ();
198238 }
199239 }
200240
201241 addList (List value) {
202- if (value != null ) {
242+ if (value != null ) {
203243 _dataList.addAll (value);
204244 notifyListeners ();
205245 }
0 commit comments