calculateSectionConfig function

SectionConfig calculateSectionConfig({
  1. required int localListLen,
  2. required int limit,
  3. required int remoteListLen,
})

Calculate the configuration for a specific space overview section for chat or space

Implementation

SectionConfig calculateSectionConfig({
  required int localListLen,
  required int limit,
  required int remoteListLen,
}) {
  int listingLimit = 0;
  bool isShowSeeAllButton = false;
  bool renderRemote = false;
  int remoteCount = 0;
  // our local list is already going beyond the limits
  if (localListLen > limit) {
    listingLimit = limit;
    isShowSeeAllButton = true;
  } else if (localListLen == limit) {
    // locally fills the list
    listingLimit = limit;
    isShowSeeAllButton = remoteListLen > 0;
  } else {
    // the local list is not filling the list
    listingLimit = localListLen;
    remoteCount = limit - localListLen;
    if (remoteCount > 0) {
      if (remoteListLen > 0) {
        renderRemote = true;
        if (remoteListLen < remoteCount) {
          remoteCount = remoteListLen;
        }
        if (remoteListLen > remoteCount) {
          isShowSeeAllButton = true;
        }
      }
    }
  }
  return SectionConfig(
    listingLimit: listingLimit,
    renderRemote: renderRemote,
    remoteCount: remoteCount,
    isShowSeeAllButton: isShowSeeAllButton,
  );
}