NsgLoadingScrollController<T> constructor
NsgLoadingScrollController<T> ({})
Implementation
NsgLoadingScrollController({this.function, this.positionBeforeLoad = 200, this.attemptCount = 1}) : super(keepScrollOffset: true) {
addListener(() async {
if (_attCount < attemptCount &&
_stat != NsgLoadingScrollStatus.loading &&
_stat != NsgLoadingScrollStatus.pause &&
(position.pixels >= position.maxScrollExtent - positionBeforeLoad)) {
_stat = NsgLoadingScrollStatus.loading;
try {
_attCount++;
if (function != null) {
Future(function!).then((T val) {
_value = val;
_stat = NsgLoadingScrollStatus.success;
});
} else {
_stat = NsgLoadingScrollStatus.empty;
}
} catch (er) {
_errCount++;
if (_errCount > 3) {
_stat = NsgLoadingScrollStatus.error;
}
}
} else if (!(position.pixels >= position.maxScrollExtent - positionBeforeLoad)) {
_attCount = 0;
_errCount = 0;
}
lastOffset = offset;
});
}