imageAndVideoItemBuilder method

  1. @override
Widget imageAndVideoItemBuilder(
  1. BuildContext context,
  2. int index,
  3. AssetEntity asset
)
override

The item builder for images and video type of asset. 图片和视频资源的部件构建

Implementation

@override
Widget imageAndVideoItemBuilder(
  BuildContext context,
  int index,
  AssetEntity asset,
) {
  return LocallyAvailableBuilder(
    asset: asset,
    isOriginal: false,
    withSubtype: false,
    thumbnailOption: ThumbnailOption(size: gridThumbnailSize),
    builder: (context, asset) {
      final imageProvider = AssetEntityImageProvider(
        asset,
        isOriginal: false,
        thumbnailSize: gridThumbnailSize,
      );
      return Stack(
        fit: StackFit.expand,
        children: <Widget>[
          RepaintBoundary(
            child: AssetEntityGridItemBuilder(
              image: imageProvider,
              failedItemBuilder: failedItemBuilder,
            ),
          ),
          FutureBuilder(
            future: imageProvider.imageFileType,
            builder: (context, snapshot) {
              if (snapshot.data case final type?
                  when type == ImageFileType.gif) {
                return gifIndicator(context, asset);
              }
              return const SizedBox.shrink();
            },
          ),
          if (asset.type == AssetType.video) // 如果为视频则显示标识
            videoIndicator(context, asset),
          if (asset.isLivePhoto) buildLivePhotoIndicator(context, asset),
        ],
      );
    },
    progressBuilder: (context, state, progress) => Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Icon(
          state == PMRequestState.failed
              ? Icons.cloud_off
              : Icons.cloud_download_outlined,
          color: context.iconTheme.color?.withOpacity(.4),
          size: 24.0,
        ),
        if (state != PMRequestState.success && state != PMRequestState.failed)
          ScaleText(
            ' ${((progress ?? 0) * 100).toInt()}%',
            style: TextStyle(
              color: context.textTheme.bodyMedium?.color?.withOpacity(.4),
              fontSize: 12.0,
            ),
          ),
      ],
    ),
  );
}