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,
        shouldAutoplayPreview: shouldAutoplayPreview,
      ),
    AssetType.image => ImagePageBuilder(
        asset: asset,
        delegate: this,
        previewThumbnailSize: previewThumbnailSize,
        shouldAutoplayPreview: shouldAutoplayPreview,
      ),
    AssetType.video => VideoPageBuilder(
        asset: asset,
        delegate: this,
        hasOnlyOneVideoAndMoment: isWeChatMoment && hasVideo,
        shouldAutoplayPreview: shouldAutoplayPreview,
      ),
    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;
        final labels = <String>[
          '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
              '${index + 1}',
          asset.createDateTime.toString().replaceAll('.000', ''),
          if (asset.type == AssetType.audio || asset.type == AssetType.video)
            '${semanticsTextDelegate.sNameDurationLabel}: '
                '${semanticsTextDelegate.durationIndicatorBuilder(asset.videoDuration)}',
          if (asset.title case final title? when title.isNotEmpty) title,
        ];
        return Semantics(
          label: labels.join(', '),
          selected: isSelected,
          image:
              asset.type == AssetType.image || asset.type == AssetType.video,
          child: w,
        );
      },
      child: builder,
    ),
  );
}