Skip to content

Commit 302585b

Browse files
committed
Merge branch 'patch-3'
2 parents 7cfe7a4 + bac5145 commit 302585b

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lib/paging.dart

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,38 @@ class Pagination<T> extends StatefulWidget {
7575
final int semanticChildCount;
7676

7777
@override
78-
_PaginationState<T> createState() => _PaginationState<T>();
78+
PaginationState<T> createState() => PaginationState<T>();
7979
}
8080

81-
class _PaginationState<T> extends State<Pagination<T>> {
81+
class PaginationState<T> extends State<Pagination<T>> {
8282
final List<T> _list = List();
8383
bool _isLoading = false;
8484
bool _isEndOfList = false;
85+
bool _justCleared = false;
86+
87+
void reset() {
88+
setState(() {
89+
_list.clear();
90+
_isLoading = false;
91+
_isEndOfList = false;
92+
_justCleared = true;
93+
});
94+
}
8595

86-
void fetchMore() {
96+
void _fetchMore() {
97+
print('\n\n\n$_isLoading$_isEndOfList$_justCleared');
98+
_justCleared = false;
8799
if (!_isLoading) {
88100
_isLoading = true;
89101
widget.pageBuilder(_list.length).then((list) {
90102
_isLoading = false;
103+
104+
// Check if the list was cleared while loading - if it was, do nothing.
105+
if (_justCleared) {
106+
_justCleared = false;
107+
return;
108+
}
109+
91110
if (list.isEmpty) {
92111
_isEndOfList = true;
93112
}
@@ -113,7 +132,7 @@ class _PaginationState<T> extends State<Pagination<T>> {
113132
@override
114133
void initState() {
115134
super.initState();
116-
fetchMore();
135+
_fetchMore();
117136
}
118137

119138
@override
@@ -135,15 +154,15 @@ class _PaginationState<T> extends State<Pagination<T>> {
135154
if (position < _list.length) {
136155
return widget.itemBuilder(position, _list.length, _list[position]);
137156
} else if (position == _list.length && !_isEndOfList) {
138-
fetchMore();
139-
return widget.progress ?? defaultLoading();
157+
_fetchMore();
158+
return widget.progress ?? _defaultLoading();
140159
}
141160
return null;
142161
},
143162
);
144163
}
145164

146-
Widget defaultLoading() {
165+
Widget _defaultLoading() {
147166
return Align(
148167
child: SizedBox(
149168
height: 40,

0 commit comments

Comments
 (0)