assetPageBuilder method
Split page builder according to type of asset. 根据资源类型使用不同的构建页
Implementation
@override
Widget assetPageBuilder(BuildContext context, int index) {
final AssetEntity asset = previewAssets.elementAt(index);
final Widget builder;
switch (asset.type) {
case AssetType.audio:
builder = AudioPageBuilder(asset: asset);
break;
case AssetType.image:
builder = ImagePageBuilder(
asset: asset,
delegate: this,
previewThumbnailSize: previewThumbnailSize,
);
break;
case AssetType.video:
builder = VideoPageBuilder(
asset: asset,
delegate: this,
hasOnlyOneVideoAndMoment: isWeChatMoment && hasVideo,
);
break;
case AssetType.other:
builder = Center(
child: ScaleText(
textDelegate.unSupportedAssetType,
semanticsLabel: semanticsTextDelegate.unSupportedAssetType,
),
);
break;
}
return MergeSemantics(
child: Consumer<AssetPickerViewerProvider<AssetEntity>?>(
builder: (
BuildContext c,
AssetPickerViewerProvider<AssetEntity>? p,
Widget? w,
) {
final bool isSelected =
(p?.currentlySelectedAssets ?? selectedAssets)?.contains(asset) ??
false;
String hint = '';
if (asset.type == AssetType.audio || asset.type == AssetType.video) {
hint += '${semanticsTextDelegate.sNameDurationLabel}: ';
hint += textDelegate.durationIndicatorBuilder(asset.videoDuration);
}
if (asset.title?.isNotEmpty ?? false) {
hint += ', ${asset.title}';
}
return Semantics(
label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
'${index + 1}, '
'${asset.createDateTime.toString().replaceAll('.000', '')}',
selected: isSelected,
hint: hint,
image:
asset.type == AssetType.image || asset.type == AssetType.video,
child: w,
);
},
child: builder,
),
);
}