imageItemBuilder method
The item builder for image type of asset
Implementation
Widget imageItemBuilder(BuildContext context, AssetEntity asset){
int defaultGridThumbSize = 200;
final AssetEntityImageProvider imageProvider = AssetEntityImageProvider(
asset,
isOriginal: false,
thumbSize: <int>[defaultGridThumbSize, defaultGridThumbSize],
);
// ConcreteCubit<bool> loading = ConcreteCubit<bool>(true);
// imageProvider.resolve(new ImageConfiguration()).addListener(ImageStreamListener(
// (_, done){
// loading.emit(false);
// }
// ));
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 lock = false;
if(provider.selectedAssets.length >= provider.maxAssets){
lock = true;
}
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,
),
),
if (provider.selectedAssets.contains(asset))
overlay != null ?
Positioned.fill(child: overlay) :
Positioned.fill(child: selectedOverlay(context, asset)),
if(!provider.selectedAssets.contains(asset) && lock)
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
),
)
],
);
}
);
}
);
}