不哭乖站起来继续写bug,Flutter bug builder 马上上代码。
无图无真相,先上一个图。 首先我们也来定义个LoadingMoreBase 契约类
class LoadingMoreBase extends ListBase
with _LoadingMoreBloc, RefreshBase {
var _array = [];
@override
T operator [](int index) {
// TODO: implement []
return _array[index];
}
@override
void operator []=(int index, T value) {
// TODO: implement []=
_array[index] = value;
}
bool get hasMore => true;
bool isLoading = false;
IndicatorStatus indicatorStatus = IndicatorStatus.None;
Future loadMore() async {
if (isLoading || !hasMore) return true;
// TODO: implement loadMore
var preStatus = indicatorStatus;
indicatorStatus = this.length == 0
? IndicatorStatus.FullScreenBusying
: IndicatorStatus.LoadingMoreBusying;
if (preStatus == IndicatorStatus.Error) {
onStateChanged(this);
}
isLoading = true;
var isSuccess = await loadData();
isLoading = false;
if (isSuccess) {
if (this.length == 0) indicatorStatus = IndicatorStatus.Empty;
} else {
indicatorStatus = IndicatorStatus.Error;
}
onStateChanged(this);
return isSuccess;
}
Future loadData() async {
return true;
}
@override
Future onRefresh() async {
// TODO: implement OnRefresh
}
@override
int get length => _array.length;
set length(int newLength) => _array.length = newLength;
@override
void onStateChanged(LoadingMoreBase source) {
// TODO: implement notice
super.onStateChanged(source);
}
}
class _LoadingMoreBloc {
final _rebuild = new StreamController<LoadingMoreBase>.broadcast();
Str