From fbb486b90ba6adba8ea597b396d493031e7284d7 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 21 Jan 2025 14:57:04 +0800 Subject: [PATCH] :lipstick: Optimized attachment list --- lib/widgets/attachment/attachment_list.dart | 83 +++++++++++---------- lib/widgets/post/post_item.dart | 2 +- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/lib/widgets/attachment/attachment_list.dart b/lib/widgets/attachment/attachment_list.dart index d221172..ff1b0d8 100644 --- a/lib/widgets/attachment/attachment_list.dart +++ b/lib/widgets/attachment/attachment_list.dart @@ -15,6 +15,7 @@ class AttachmentList extends StatefulWidget { final List data; final bool bordered; final bool gridded; + final bool columned; final BoxFit fit; final double? maxHeight; final double? minWidth; @@ -26,6 +27,7 @@ class AttachmentList extends StatefulWidget { required this.data, this.bordered = false, this.gridded = false, + this.columned = false, this.fit = BoxFit.cover, this.maxHeight, this.minWidth, @@ -105,45 +107,10 @@ class _AttachmentListState extends State { ); } - if (widget.gridded) { - final fullOfImage = - widget.data.where((ele) => ele?.mediaType == SnMediaType.image).length == widget.data.length; - if (!fullOfImage) { - return Container( - margin: widget.padding ?? EdgeInsets.zero, - decoration: BoxDecoration( - color: backgroundColor, - border: Border( - top: borderSide, - bottom: borderSide, - ), - borderRadius: AttachmentList.kDefaultRadius, - ), - child: ClipRRect( - borderRadius: AttachmentList.kDefaultRadius, - child: Column( - spacing: 4, - children: widget.data - .mapIndexed( - (idx, ele) => GestureDetector( - child: AspectRatio( - aspectRatio: ele?.data['ratio']?.toDouble() ?? 1, - child: Container( - constraints: constraints, - child: AttachmentItem( - data: ele, - heroTag: heroTags[idx], - fit: BoxFit.cover, - ), - ), - ), - ), - ) - .toList(), - ), - ), - ); - } + final fullOfImage = + widget.data.where((ele) => ele?.mediaType == SnMediaType.image).length == widget.data.length; + + if (widget.gridded && fullOfImage) { return Container( margin: widget.padding ?? EdgeInsets.zero, decoration: BoxDecoration( @@ -191,6 +158,44 @@ class _AttachmentListState extends State { ); } + if ((!fullOfImage && widget.gridded) || widget.columned) { + return Container( + margin: widget.padding ?? EdgeInsets.zero, + decoration: BoxDecoration( + color: backgroundColor, + border: Border( + top: borderSide, + bottom: borderSide, + ), + borderRadius: AttachmentList.kDefaultRadius, + ), + child: ClipRRect( + borderRadius: AttachmentList.kDefaultRadius, + child: Column( + children: widget.data + .mapIndexed( + (idx, ele) => GestureDetector( + child: AspectRatio( + aspectRatio: ele?.data['ratio']?.toDouble() ?? 1, + child: Container( + constraints: constraints, + child: AttachmentItem( + data: ele, + heroTag: heroTags[idx], + fit: BoxFit.cover, + ), + ), + ), + ), + ) + .expand((ele) => [ele, const Divider(height: 1)]) + .toList() + ..removeLast(), + ), + ), + ); + } + return AspectRatio( aspectRatio: widget.data.isNotEmpty ? widget.data.first?.data['ratio']?.toDouble() ?? 1 : 1, child: Container( diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 02853bb..47c6098 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -343,7 +343,7 @@ class PostShareImageWidget extends StatelessWidget { if (data.type != 'article' && (data.preload?.attachments?.isNotEmpty ?? false)) StyledWidget(AttachmentList( data: data.preload!.attachments!, - gridded: true, + columned: true, )).padding(horizontal: 16, bottom: 8), Column( crossAxisAlignment: CrossAxisAlignment.start,