viewAsset method
Determine how to browse assets in the viewer. 定义如何在查看器中浏览资源
Implementation
@override
Future<void> viewAsset(
BuildContext context,
int? index,
AssetEntity currentAsset,
) async {
final p = context.read<DefaultAssetPickerProvider>();
// - When we reached the maximum select count and the asset is not selected,
// do nothing.
// - When the special type is WeChat Moment, pictures and videos cannot
// be selected at the same time. Video select should be banned if any
// pictures are selected.
if ((!p.selectedAssets.contains(currentAsset) && p.selectedMaximumAssets) ||
(isWeChatMoment &&
currentAsset.type == AssetType.video &&
p.selectedAssets.isNotEmpty)) {
return;
}
final revert = effectiveShouldRevertGrid(context);
List<AssetEntity> current;
final List<AssetEntity>? selected;
final int effectiveIndex;
if (isWeChatMoment) {
if (currentAsset.type == AssetType.video) {
current = <AssetEntity>[currentAsset];
selected = null;
effectiveIndex = 0;
} else {
if (index == null) {
current = p.selectedAssets;
current = current.reversed.toList(growable: false);
} else {
current = p.currentAssets;
}
current = current
.where((AssetEntity e) => e.type == AssetType.image)
.toList();
selected = p.selectedAssets;
final i = current.indexOf(currentAsset);
effectiveIndex = revert ? current.length - i - 1 : i;
}
} else {
selected = p.selectedAssets;
if (index == null) {
current = p.selectedAssets;
if (revert) {
current = current.reversed.toList(growable: false);
}
effectiveIndex = selected.indexOf(currentAsset);
} else {
current = p.currentAssets;
effectiveIndex = revert ? current.length - index - 1 : index;
}
}
final List<AssetEntity>? result = await AssetPickerViewer.pushToViewer(
context,
currentIndex: effectiveIndex,
previewAssets: current,
themeData: theme,
previewThumbnailSize: previewThumbnailSize,
selectPredicate: selectPredicate,
selectedAssets: selected,
selectorProvider: p,
specialPickerType: specialPickerType,
maxAssets: p.maxAssets,
shouldReversePreview: revert,
);
if (result != null) {
Navigator.maybeOf(context)?.maybePop(result);
}
}