💄 Optimize attachment list

This commit is contained in:
LittleSheep 2025-01-28 20:39:34 +08:00
parent 5c2804cc4d
commit 1e8a6dea5b

View File

@ -196,68 +196,71 @@ class _AttachmentListState extends State<AttachmentList> {
); );
} }
return Container( return AspectRatio(
constraints: BoxConstraints(maxHeight: constraints.maxHeight), aspectRatio: widget.data[0]?.data['ratio']?.toDouble() ?? 1,
child: ScrollConfiguration( child: Container(
behavior: _AttachmentListScrollBehavior(), constraints: BoxConstraints(maxHeight: constraints.maxHeight),
child: ListView.separated( child: ScrollConfiguration(
padding: widget.padding, behavior: _AttachmentListScrollBehavior(),
shrinkWrap: true, child: ListView.separated(
itemCount: widget.data.length, padding: widget.padding,
itemBuilder: (context, idx) { shrinkWrap: true,
return Container( itemCount: widget.data.length,
constraints: constraints.copyWith(maxWidth: widget.maxWidth), itemBuilder: (context, idx) {
child: AspectRatio( return Container(
aspectRatio: (widget.data[idx]?.data['ratio'] ?? 1).toDouble(), constraints: constraints.copyWith(maxWidth: widget.maxWidth),
child: GestureDetector( child: AspectRatio(
onTap: () { aspectRatio: (widget.data[idx]?.data['ratio'] ?? 1).toDouble(),
if (widget.data[idx]?.mediaType != SnMediaType.image) return; child: GestureDetector(
context.pushTransparentRoute( onTap: () {
AttachmentZoomView( if (widget.data[idx]?.mediaType != SnMediaType.image) return;
data: widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(), context.pushTransparentRoute(
initialIndex: idx, AttachmentZoomView(
heroTags: heroTags, data: widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(),
), initialIndex: idx,
backgroundColor: Colors.black.withOpacity(0.7), heroTags: heroTags,
rootNavigator: true,
);
},
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border(
top: borderSide,
bottom: borderSide,
),
borderRadius: AttachmentList.kDefaultRadius,
), ),
child: ClipRRect( backgroundColor: Colors.black.withOpacity(0.7),
borderRadius: AttachmentList.kDefaultRadius, rootNavigator: true,
child: AttachmentItem( );
data: widget.data[idx], },
heroTag: heroTags[idx], child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border(
top: borderSide,
bottom: borderSide,
),
borderRadius: AttachmentList.kDefaultRadius,
),
child: ClipRRect(
borderRadius: AttachmentList.kDefaultRadius,
child: AttachmentItem(
data: widget.data[idx],
heroTag: heroTags[idx],
),
), ),
), ),
), Positioned(
Positioned( right: 8,
right: 8, bottom: 8,
bottom: 8, child: Chip(
child: Chip( label: Text('${idx + 1}/${widget.data.length}'),
label: Text('${idx + 1}/${widget.data.length}'), ),
), ),
), ],
], ),
), ),
), ),
), );
); },
}, separatorBuilder: (context, index) => const Gap(8),
separatorBuilder: (context, index) => const Gap(8), physics: const BouncingScrollPhysics(),
physics: const BouncingScrollPhysics(), scrollDirection: Axis.horizontal,
scrollDirection: Axis.horizontal, ),
), ),
), ),
); );