assetPageBuilder method

  1. @override
Widget assetPageBuilder(
  1. BuildContext context,
  2. int index
)
override

Split page builder according to type of asset. 根据资源类型使用不同的构建页

Implementation

@override
Widget assetPageBuilder(BuildContext context, int index) {
  final AssetEntity asset = previewAssets.elementAt(
    shouldReversePreview ? previewAssets.length - index - 1 : index,
  );
  final Widget builder = switch (asset.type) {
    AssetType.audio => AudioPageBuilder(asset: asset),
    AssetType.image => ImagePageBuilder(
        asset: asset,
        delegate: this,
        previewThumbnailSize: previewThumbnailSize,
      ),
    AssetType.video => VideoPageBuilder(
        asset: asset,
        delegate: this,
        hasOnlyOneVideoAndMoment: isWeChatMoment && hasVideo,
      ),
    AssetType.other => Center(
        child: ScaleText(
          textDelegate.unSupportedAssetType,
          semanticsLabel: semanticsTextDelegate.unSupportedAssetType,
        ),
      ),
  };
  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,
    ),
  );
}