load method

void load(
  1. bool isFirst,
  2. List<T>? current,
  3. bool append,
  4. bool skeletal,
  5. C? cursor, {
  6. Function? onLoadComplete,
})

Implementation

void load(bool isFirst, List<T>? current, bool append, bool skeletal, C? cursor, {Function? onLoadComplete}) async{
  ListResult<T, C> newModel;
  if(callback != null){
    logNUI("NUIListViewBloc", "Callback is not null, loading with callback for type: $T");
    newModel = await callback!.load(isFirst: isFirst, current: current, append: append, cursor: cursor);
  }
  else{
    logNUI("NUIListViewBloc", "Callback invoke is not null, loading with callback invoke for type: $T");
    newModel = await callbackMethod!(current, isFirst, append, cursor);
  }

  List<T> newList = <T>[];
  if(append && isFirst != true){
    newList.addAll(current ?? []);
  }
  if(!isNullOrEmpty(newModel.data)) {
    newList.addAll(newModel.data);
  }
  if(onLoadComplete != null) onLoadComplete();
  final newListModel = NUIListViewModel<T, C>(
      skeletalLoading: false,
      paginationLoading:false,
      swipeRefreshing:false,
      reachedEnd: newModel.reachedEnd,
      appending: append && isFirst != true,
      success: newModel.success,
      message: newModel.message,
      errorCode: newModel.errorCode,
      data: newList,
      newData: newModel.data,
      cursor: newModel.cursor,
      updateCheckedMap: newModel.updateCheckedMap,
      updateConfigMap: newModel.updateConfigMap
  );

  logNUI("NUIListViewBloc", "Loading completed, new model id : ${newListModel.id} for type : $T");

  notify(newListModel);
}