assetGridItemSemanticsBuilder method
Widget
assetGridItemSemanticsBuilder(
- BuildContext context,
- int index,
- AssetEntity asset,
- Widget child,
override
The Semantics builder for the assets' grid. 资源列表项的语义构建
Implementation
@override
Widget assetGridItemSemanticsBuilder(
BuildContext context,
int index,
AssetEntity asset,
Widget child,
) {
return ValueListenableBuilder<bool>(
valueListenable: isSwitchingPath,
builder: (_, bool isSwitchingPath, Widget? child) {
return Consumer<DefaultAssetPickerProvider>(
builder: (_, DefaultAssetPickerProvider p, __) {
final bool isBanned = (!p.selectedAssets.contains(asset) &&
p.selectedMaximumAssets) ||
(isWeChatMoment &&
asset.type == AssetType.video &&
p.selectedAssets.isNotEmpty);
final bool isSelected = p.selectedDescriptions.contains(
asset.toString(),
);
final int selectedIndex = p.selectedAssets.indexOf(asset) + 1;
String hint = '';
if (asset.type == AssetType.audio ||
asset.type == AssetType.video) {
hint += '${semanticsTextDelegate.sNameDurationLabel}: ';
hint += semanticsTextDelegate.durationIndicatorBuilder(
asset.videoDuration,
);
}
if (asset.title?.isNotEmpty ?? false) {
hint += ', ${asset.title}';
}
return Semantics(
button: false,
enabled: !isBanned,
excludeSemantics: true,
focusable: !isSwitchingPath,
label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
'${semanticIndex(index)}, '
'${asset.createDateTime.toString().replaceAll('.000', '')}',
hidden: isSwitchingPath,
hint: hint,
image: asset.type == AssetType.image ||
asset.type == AssetType.video,
onTap: () => selectAsset(context, asset, index, isSelected),
onTapHint: semanticsTextDelegate.sActionSelectHint,
onLongPress: isPreviewEnabled
? () => viewAsset(context, index, asset)
: null,
onLongPressHint: semanticsTextDelegate.sActionPreviewHint,
selected: isSelected,
sortKey: OrdinalSortKey(
semanticIndex(index).toDouble(),
name: 'GridItem',
),
value: selectedIndex > 0 ? '$selectedIndex' : null,
child: GestureDetector(
// Regression https://github.com/flutter/flutter/issues/35112.
onLongPress:
isPreviewEnabled && context.mediaQuery.accessibleNavigation
? () => viewAsset(context, index, asset)
: null,
child: IndexedSemantics(
index: semanticIndex(index),
child: child,
),
),
);
},
);
},
child: child,
);
}