videoItemBuilder method

Widget videoItemBuilder(
  1. BuildContext context,
  2. AssetEntity asset
)

The item builder for video type of asset

Implementation

Widget videoItemBuilder(BuildContext context, AssetEntity asset){

  int defaultGridThumbSize = 200;

  final AssetEntityImageProvider imageProvider = AssetEntityImageProvider(
    asset,
    isOriginal: false,
    thumbSize: <int>[defaultGridThumbSize, defaultGridThumbSize],
  );

  return Selector<DefaultAssetPickerProvider, int>(
    selector: (_, DefaultAssetPickerProvider p) => p.maxAssets,
    builder: (BuildContext context, int count, Widget? child) {
      return Selector<DefaultAssetPickerProvider, int>(
        selector: (_, DefaultAssetPickerProvider p) => p.selectedAssets.length,
        builder: (BuildContext context, int selectedCount, Widget? child) {
          bool videoLock = false;
          bool lock = false;
          if(provider.selectedAssets.length >= provider.maxAssets){
            lock = true;
          }
          else if(provider.selectedAssets.where((element) => element.duration > 0).isNotEmpty){
            videoLock = true;
          }

          final String duration = asset.videoDuration.toString().split('.')[0].substring(3);
          final Widget? videoIndicator = delegate.videoIndicator(context, duration);
          final Widget? overlay = delegate.overlayBuilder(context, provider.selectedAssets.indexOf(asset) + 1);
          final Widget? lockOverlay = delegate.lockOverlayBuilder(context, provider.selectedAssets.indexOf(asset) + 1);

          return Stack(
            children: [
              delegate.tileLoadingIndicator(context) ?? Container(
                decoration: BoxDecoration(
                  color: Colors.grey,
                  border: provider.selectedAssets.contains(asset) ? Border.all(width: 2, color: Colors.white.withOpacity(0.5)) : null
                ),
              ),
              Positioned.fill(
                child: AssetEntityGridItemBuilder(
                  image: imageProvider,
                  failedItemBuilder: failedItemBuilder,
                ),
              ),
              Align(
                alignment: Alignment.bottomRight,
                child: Padding(
                  padding: const EdgeInsets.only(bottom: 2, right: 2),
                  child: videoIndicator == null ? Container(
                    height: 16,
                    width: 32,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      color: Colors.black.withOpacity(0.5),
                    ),
                    child: Center(
                        child: Text(
                          duration,
                          style: TextStyle(
                            color: Colors.white.withOpacity(0.8),
                            fontSize: 12
                        ),
                      )
                    ),
                  ) : videoIndicator,
                ),
              ),
              if (provider.selectedAssets.contains(asset))
              overlay != null ? Positioned.fill(child: overlay) : Positioned.fill(child: selectedOverlay(context, asset)),
              if(!provider.selectedAssets.contains(asset) && (lock || videoLock))
              lockOverlay != null ? Positioned.fill(child: lockOverlay) : greyOverlay(context, asset),
              Container(
                decoration: BoxDecoration(
                  color: Colors.transparent,
                  border: provider.selectedAssets.contains(asset) ? Border.all(width: 2, color: Colors.white.withOpacity(0.5)) : null
                )),
            ],
          );
        }
      );
    }
  );
}