diff --git a/example/lib/customs/pickers/directory_file_asset_picker.dart b/example/lib/customs/pickers/directory_file_asset_picker.dart index ef487b64..0fc2d2ef 100644 --- a/example/lib/customs/pickers/directory_file_asset_picker.dart +++ b/example/lib/customs/pickers/directory_file_asset_picker.dart @@ -645,7 +645,7 @@ class FileAssetPickerBuilder id: key.value, assets: assets, placeholderCount: placeholderCount, - prependSpecialItemResults: specialItemModels + specialItemModels: specialItemModels .where( (item) => item.position == SpecialItemPosition.prepend, ) @@ -775,7 +775,7 @@ class FileAssetPickerBuilder int index, File asset, Widget child, - List prependSpecialItemResults, + List specialItemModels, ) { return Semantics(child: child); } @@ -1213,7 +1213,7 @@ class FileAssetPickerBuilder int findChildIndexBuilder({ required String id, required List assets, - required List prependSpecialItemResults, + required List specialItemModels, int placeholderCount = 0, }) { return assets.indexWhere((File file) => file.path == id); diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index c1bcec3c..41333b7a 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -330,7 +330,7 @@ abstract class AssetPickerBuilderDelegate { int? findChildIndexBuilder({ required String id, required List assets, - required List prependSpecialItemResults, + required List specialItemModels, int placeholderCount = 0, }) => null; @@ -358,7 +358,7 @@ abstract class AssetPickerBuilderDelegate { int index, Asset asset, Widget child, - List prependSpecialItemResults, + List specialItemModels, ); /// The item builder for audio type of asset. @@ -1317,12 +1317,7 @@ class DefaultAssetPickerBuilderDelegate id: key.value, assets: assets, placeholderCount: placeholderCount, - prependSpecialItemResults: specialItemModels - .where( - (item) => - item.position == SpecialItemPosition.prepend, - ) - .toList(), + specialItemModels: specialItemModels, ); } return null; @@ -1492,15 +1487,18 @@ class DefaultAssetPickerBuilderDelegate index, asset, content, - prependItems, + specialItemModels, ); } int semanticIndex( int index, - List prependSpecialItemResults, + List specialItemModels, ) { - return index - prependSpecialItemResults.length; + final prependSpecialItemModels = specialItemModels.where( + (SpecialItemModel model) => model.position == SpecialItemPosition.prepend, + ); + return index - prependSpecialItemModels.length; } @override @@ -1509,7 +1507,7 @@ class DefaultAssetPickerBuilderDelegate int index, AssetEntity asset, Widget child, - List prependSpecialItemResults, + List specialItemModels, ) { return ValueListenableBuilder( valueListenable: isSwitchingPath, @@ -1543,7 +1541,7 @@ class DefaultAssetPickerBuilderDelegate excludeSemantics: true, focusable: !isSwitchingPath, label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}' - '${semanticIndex(index, prependSpecialItemResults)}, ' + '${semanticIndex(index, specialItemModels)}, ' '${asset.createDateTime.toString().replaceAll('.000', '')}', hidden: isSwitchingPath, hint: hint, @@ -1561,7 +1559,7 @@ class DefaultAssetPickerBuilderDelegate onLongPressHint: semanticsTextDelegate.sActionPreviewHint, selected: isSelected, sortKey: OrdinalSortKey( - semanticIndex(index, prependSpecialItemResults).toDouble(), + semanticIndex(index, specialItemModels).toDouble(), name: 'GridItem', ), value: selectedIndex > 0 ? '$selectedIndex' : null, @@ -1574,7 +1572,7 @@ class DefaultAssetPickerBuilderDelegate } : null, child: IndexedSemantics( - index: semanticIndex(index, prependSpecialItemResults), + index: semanticIndex(index, specialItemModels), child: child, ), ), @@ -1590,11 +1588,14 @@ class DefaultAssetPickerBuilderDelegate int findChildIndexBuilder({ required String id, required List assets, - required List prependSpecialItemResults, + required List specialItemModels, int placeholderCount = 0, }) { + final prependSpecialItemModels = specialItemModels.where( + (SpecialItemModel model) => model.position == SpecialItemPosition.prepend, + ); int index = assets.indexWhere((AssetEntity e) => e.id == id); - index += prependSpecialItemResults.length; + index += prependSpecialItemModels.length; index += placeholderCount; return index; }