Skip to content

Commit

Permalink
Use specialItemModels as args.
Browse files Browse the repository at this point in the history
  • Loading branch information
yujunetee committed Dec 11, 2024
1 parent 38cc19f commit f310550
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions example/lib/customs/pickers/directory_file_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class FileAssetPickerBuilder
id: key.value,
assets: assets,
placeholderCount: placeholderCount,
prependSpecialItemResults: specialItemModels
specialItemModels: specialItemModels
.where(
(item) => item.position == SpecialItemPosition.prepend,
)
Expand Down Expand Up @@ -775,7 +775,7 @@ class FileAssetPickerBuilder
int index,
File asset,
Widget child,
List<SpecialItemModel> prependSpecialItemResults,
List<SpecialItemModel> specialItemModels,
) {
return Semantics(child: child);
}
Expand Down Expand Up @@ -1213,7 +1213,7 @@ class FileAssetPickerBuilder
int findChildIndexBuilder({
required String id,
required List<File> assets,
required List<SpecialItemModel> prependSpecialItemResults,
required List<SpecialItemModel> specialItemModels,
int placeholderCount = 0,
}) {
return assets.indexWhere((File file) => file.path == id);
Expand Down
35 changes: 18 additions & 17 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
int? findChildIndexBuilder({
required String id,
required List<Asset> assets,
required List<SpecialItemModel> prependSpecialItemResults,
required List<SpecialItemModel> specialItemModels,
int placeholderCount = 0,
}) =>
null;
Expand Down Expand Up @@ -358,7 +358,7 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
int index,
Asset asset,
Widget child,
List<SpecialItemModel> prependSpecialItemResults,
List<SpecialItemModel> specialItemModels,
);

/// The item builder for audio type of asset.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1492,15 +1487,18 @@ class DefaultAssetPickerBuilderDelegate
index,
asset,
content,
prependItems,
specialItemModels,
);
}

int semanticIndex(
int index,
List<SpecialItemModel> prependSpecialItemResults,
List<SpecialItemModel> specialItemModels,
) {
return index - prependSpecialItemResults.length;
final prependSpecialItemModels = specialItemModels.where(
(SpecialItemModel model) => model.position == SpecialItemPosition.prepend,
);
return index - prependSpecialItemModels.length;
}

@override
Expand All @@ -1509,7 +1507,7 @@ class DefaultAssetPickerBuilderDelegate
int index,
AssetEntity asset,
Widget child,
List<SpecialItemModel> prependSpecialItemResults,
List<SpecialItemModel> specialItemModels,
) {
return ValueListenableBuilder<bool>(
valueListenable: isSwitchingPath,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -1574,7 +1572,7 @@ class DefaultAssetPickerBuilderDelegate
}
: null,
child: IndexedSemantics(
index: semanticIndex(index, prependSpecialItemResults),
index: semanticIndex(index, specialItemModels),
child: child,
),
),
Expand All @@ -1590,11 +1588,14 @@ class DefaultAssetPickerBuilderDelegate
int findChildIndexBuilder({
required String id,
required List<AssetEntity> assets,
required List<SpecialItemModel> prependSpecialItemResults,
required List<SpecialItemModel> 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;
}
Expand Down

0 comments on commit f310550

Please sign in to comment.