assetsGridItemPlaceholderCount method

int assetsGridItemPlaceholderCount({
  1. required BuildContext context,
  2. required PathWrapper<Path>? pathWrapper,
  3. required bool onlyOneScreen,
})

Calculates the placeholder count in the assets grid.

Implementation

int assetsGridItemPlaceholderCount({
  required BuildContext context,
  required PathWrapper<Path>? pathWrapper,
  required bool onlyOneScreen,
}) {
  if (onlyOneScreen) {
    return 0;
  }
  final bool gridRevert = effectiveShouldRevertGrid(context);
  int totalCount = pathWrapper?.assetCount ?? 0;
  // If user chose a special item's position, add 1 count.
  if (specialItemPosition != SpecialItemPosition.none) {
    final specialItem = specialItemBuilder?.call(
      context,
      pathWrapper?.path,
      totalCount,
    );
    if (specialItem != null) {
      totalCount += 1;
    }
  }
  final int result;
  if (gridRevert && totalCount % gridCount != 0) {
    // When there are left items that not filled into one row,
    // filled the row with placeholders.
    result = gridCount - totalCount % gridCount;
  } else {
    // Otherwise, we don't need placeholders.
    result = 0;
  }
  return result;
}