bottomDetailItemBuilder method
Thumb item widgets in bottom detail. 底部信息栏单个资源缩略部件
Implementation
@override
Widget bottomDetailItemBuilder(BuildContext context, int index) {
const double padding = 8.0;
void onTap(AssetEntity asset) {
int page;
if (previewAssets != selectedAssets) {
page = previewAssets.indexOf(asset);
} else {
page = index;
}
if (shouldReversePreview) {
page = previewAssets.length - page - 1;
}
if (pageController.page == page.toDouble()) {
return;
}
pageController.jumpToPage(page);
final double offset =
(index - 0.5) * (bottomPreviewHeight - padding * 3) -
MediaQuery.sizeOf(context).width / 4;
previewingListController.animateTo(
math.max(0, offset),
curve: Curves.ease,
duration: kThemeChangeDuration,
);
}
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: padding,
vertical: padding * 2,
),
child: AspectRatio(
aspectRatio: 1.0,
child: StreamBuilder<int>(
initialData: currentIndex,
stream: pageStreamController.stream,
builder: (_, AsyncSnapshot<int> snapshot) {
final AssetEntity asset = selectedAssets!.elementAt(index);
final viewingIndex = shouldReversePreview
? previewAssets.length - snapshot.data! - 1
: snapshot.data!;
final bool isViewing = previewAssets[viewingIndex] == asset;
final Widget item = switch (asset.type) {
AssetType.image => _imagePreviewItem(asset),
AssetType.video => _videoPreviewItem(asset),
AssetType.audio => _audioPreviewItem(asset),
AssetType.other => const SizedBox.shrink(),
};
return Semantics(
label: '${semanticsTextDelegate.semanticTypeLabel(asset.type)}'
'${index + 1}',
selected: isViewing,
onTap: () {
onTap(asset);
},
onTapHint: semanticsTextDelegate.sActionPreviewHint,
excludeSemantics: true,
child: GestureDetector(
onTap: () {
onTap(asset);
},
child: Selector<AssetPickerViewerProvider<AssetEntity>?,
List<AssetEntity>?>(
selector: (_, AssetPickerViewerProvider<AssetEntity>? p) =>
p?.currentlySelectedAssets,
child: item,
builder: (
_,
List<AssetEntity>? currentlySelectedAssets,
Widget? w,
) {
final bool isSelected =
currentlySelectedAssets?.contains(asset) ?? false;
return Stack(
children: <Widget>[
w!,
AnimatedContainer(
duration: kThemeAnimationDuration,
curve: Curves.easeInOut,
decoration: BoxDecoration(
border: isViewing
? Border.all(
color: themeData.colorScheme.secondary,
width: 3,
)
: null,
color: isSelected
? null
: themeData.colorScheme.surface
.withOpacity(0.54),
),
),
],
);
},
),
),
);
},
),
),
);
}