assetsGridItemCount method
int
assetsGridItemCount({
- required BuildContext context,
- required List<
AssetEntity> assets, - int placeholderCount = 0,
- Widget? specialItem,
override
The function which return items count for the assets' grid. 为资源列表提供内容数量计算的方法
Implementation
@override
int assetsGridItemCount({
required BuildContext context,
required List<AssetEntity> assets,
int placeholderCount = 0,
Widget? specialItem,
}) {
final PathWrapper<AssetPathEntity>? currentWrapper = context
.select<DefaultAssetPickerProvider, PathWrapper<AssetPathEntity>?>(
(DefaultAssetPickerProvider p) => p.currentPath,
);
final AssetPathEntity? currentPathEntity = currentWrapper?.path;
final int length = assets.length + placeholderCount;
// Return 1 if the [specialItem] build something.
if (currentPathEntity == null && specialItem != null) {
return placeholderCount + 1;
}
// Return actual length if the current path is all.
// 如果当前目录是全部内容,则返回实际的内容数量。
if (currentPathEntity?.isAll != true && specialItem == null) {
return length;
}
return switch (specialItemPosition) {
SpecialItemPosition.none => length,
SpecialItemPosition.prepend || SpecialItemPosition.append => length + 1,
};
}