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) {
final int page;
if (previewAssets != selectedAssets) {
page = previewAssets.indexOf(asset);
} else {
page = index;
}
if (pageController.page == page.toDouble()) {
return;
}
pageController.jumpToPage(page);
final double offset =
(index - 0.5) * (bottomPreviewHeight - padding * 3) -
context.mediaQuery.size.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 bool isViewing = previewAssets[snapshot.data!] == asset;
final Widget item = () {
switch (asset.type) {
case AssetType.image:
return _imagePreviewItem(asset);
case AssetType.video:
return _videoPreviewItem(asset);
case AssetType.audio:
return _audioPreviewItem(asset);
case AssetType.other:
return 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),
),
),
],
);
},
),
),
);
},
),
),
);
}