updateList method
Implementation
Widget updateList(){
final model = curModel;
//Update checked list and config list if specified
if(model.updateCheckedMap != null) model.updateCheckedMap!(checkedMap);
if(model.updateConfigMap != null) model.updateConfigMap!(configMap);
curModel = model;
_refreshController?.refreshCompleted();
if (model.paginationLoading) {
// Handle progress state
addPaginationIfNotAdded();
return buildList();
}
else if(model.skeletalLoading){
clearItems();
//Add number of skeletal (null) models into the list according to the skeletal count specified
for(int i = 0; i < (widget.skeletalCount ?? 0); i++){
addItem(null);
}
return buildList();
}
else if(model.success == false && isNullOrEmpty(model.data) && widget.errorHolder != null){
return customScroll() == true ? buildList(otherView: getErrorHolder(model)!) : getErrorHolder(model)!;
}
else if(isNullOrEmpty(model.data) && widget.placeHolder != null){
return customScroll() == true ? buildList(otherView: getPlaceHolder()!) : getPlaceHolder()!;
}
else {
// Handle data state
if (!modelChanged){
//Model not changed, so do nothing
logNUI("NUIListInterface", "List model hasn't changed, probably just a setState()");
}
else if (model.appending != true || items.isNullOrEmpty()) {
logNUI("NUIListInterface", "New list model loaded");
//New set of data
clearItems();
final toAddList = [];
if (fixedFirstItem != null) {
toAddList.add(fixedFirstItem);
}
toAddList.addAll(model.data ?? []);
if (fixedLastItem != null) {
toAddList.add(fixedLastItem);
}
addItems(toAddList);
}
else {
logNUI("NUIListInterface", "New list model being appended");
//Appending from current list
if (items.getOrNull(items.length - 1) == null){
logNUI("NUIListInterface", "Removing skeletal item before adding new items");
removeItemAt(items.length - 1);
}
if(items.getOrNull(items.length - 1) == fixedLastItem){
logNUI("NUIListInterface", "Removing fixed last item before adding new items");
removeItemAt(items.length - 1);
}
if(items.getOrNull(items.length - 1) == pagination){
logNUI("NUIListInterface", "Removing pagination before adding new items");
removeItemAt(items.length - 1);
}
final toAddList = [];
toAddList.addAll(model.newData ?? []);
if (fixedLastItem != null) {
toAddList.add(fixedLastItem);
}
addItems(toAddList);
}
items.remove(pagination);
//If prev model is null, set it as the cur model
if(prevModel == null){
prevModel = prevModel = curModel;
}
return buildList();
}
}