From bb7b731602d6679a5be2ecd0c32e9a9152d71083 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 21 Jan 2025 12:12:21 +0800 Subject: [PATCH] :rewind: Rollback to old style attachment list --- lib/widgets/attachment/attachment_list.dart | 118 ++++++++--------- lib/widgets/attachment/attachment_zoom.dart | 132 ++++++++++---------- lib/widgets/link_preview.dart | 9 +- lib/widgets/post/post_item.dart | 3 +- 4 files changed, 135 insertions(+), 127 deletions(-) diff --git a/lib/widgets/attachment/attachment_list.dart b/lib/widgets/attachment/attachment_list.dart index 0d3a9bd..d221172 100644 --- a/lib/widgets/attachment/attachment_list.dart +++ b/lib/widgets/attachment/attachment_list.dart @@ -108,7 +108,7 @@ class _AttachmentListState extends State { if (widget.gridded) { final fullOfImage = widget.data.where((ele) => ele?.mediaType == SnMediaType.image).length == widget.data.length; - if(!fullOfImage) { + if (!fullOfImage) { return Container( margin: widget.padding ?? EdgeInsets.zero, decoration: BoxDecoration( @@ -191,68 +191,72 @@ class _AttachmentListState extends State { ); } - return Container( - constraints: BoxConstraints(maxHeight: constraints.maxHeight), - child: ScrollConfiguration( - behavior: _AttachmentListScrollBehavior(), - child: ListView.separated( - padding: widget.padding, - shrinkWrap: true, - itemCount: widget.data.length, - itemBuilder: (context, idx) { - return Container( - constraints: constraints.copyWith(maxWidth: widget.maxWidth), - child: AspectRatio( - aspectRatio: (widget.data[idx]?.data['ratio'] ?? 1).toDouble(), - child: GestureDetector( - onTap: () { - if (widget.data[idx]?.mediaType != SnMediaType.image) return; - context.pushTransparentRoute( - AttachmentZoomView( - data: widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(), - initialIndex: idx, - heroTags: heroTags, - ), - backgroundColor: Colors.black.withOpacity(0.7), - rootNavigator: true, - ); - }, - child: Stack( - fit: StackFit.expand, - children: [ - Container( - decoration: BoxDecoration( - color: backgroundColor, - border: Border( - top: borderSide, - bottom: borderSide, - ), - borderRadius: AttachmentList.kDefaultRadius, + return AspectRatio( + aspectRatio: widget.data.isNotEmpty ? widget.data.first?.data['ratio']?.toDouble() ?? 1 : 1, + child: Container( + constraints: constraints, + child: ScrollConfiguration( + behavior: _AttachmentListScrollBehavior(), + child: ListView.separated( + padding: widget.padding, + shrinkWrap: true, + itemCount: widget.data.length, + itemBuilder: (context, idx) { + return Container( + constraints: constraints.copyWith(maxWidth: widget.maxWidth), + child: AspectRatio( + aspectRatio: (widget.data[idx]?.data['ratio'] ?? 1).toDouble(), + child: GestureDetector( + onTap: () { + if (widget.data[idx]?.mediaType != SnMediaType.image) return; + context.pushTransparentRoute( + AttachmentZoomView( + data: + widget.data.where((ele) => ele != null && ele.mediaType == SnMediaType.image).cast(), + initialIndex: idx, + heroTags: heroTags, ), - child: ClipRRect( - borderRadius: AttachmentList.kDefaultRadius, - child: AttachmentItem( - data: widget.data[idx], - heroTag: heroTags[idx], + backgroundColor: Colors.black.withOpacity(0.7), + rootNavigator: true, + ); + }, + 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( - right: 8, - bottom: 8, - child: Chip( - label: Text('${idx + 1}/${widget.data.length}'), + Positioned( + right: 8, + bottom: 8, + child: Chip( + label: Text('${idx + 1}/${widget.data.length}'), + ), ), - ), - ], + ], + ), ), ), - ), - ); - }, - separatorBuilder: (context, index) => const Gap(8), - physics: const BouncingScrollPhysics(), - scrollDirection: Axis.horizontal, + ); + }, + separatorBuilder: (context, index) => const Gap(8), + physics: const BouncingScrollPhysics(), + scrollDirection: Axis.horizontal, + ), ), ), ); diff --git a/lib/widgets/attachment/attachment_zoom.dart b/lib/widgets/attachment/attachment_zoom.dart index 0252b98..1289ff6 100644 --- a/lib/widgets/attachment/attachment_zoom.dart +++ b/lib/widgets/attachment/attachment_zoom.dart @@ -415,77 +415,79 @@ class _AttachmentZoomDetailPopup extends StatelessWidget { ], ).padding(horizontal: 20, top: 16, bottom: 12), Expanded( - child: Table( - columnWidths: { - 0: IntrinsicColumnWidth(), - 1: FlexColumnWidth(), - }, - children: [ - TableRow( - children: [ - TableCell( - child: Text('attachmentUploadBy').tr().padding(right: 16), - ), - TableCell( - child: Row( - children: [ - if (data.accountId > 0) - AccountImage( - content: account?.avatar, - radius: 8, - ), - const Gap(8), - Text(data.accountId > 0 ? account?.nick ?? 'unknown'.tr() : 'unknown'.tr()), - const Gap(8), - Text('#${data.accountId}', style: GoogleFonts.robotoMono()).opacity(0.75), - ], - ), - ), - ], - ), - tableGap, - TableRow( - children: [ - TableCell(child: Text('Mimetype').padding(right: 16)), - TableCell(child: Text(data.mimetype)), - ], - ), - TableRow( - children: [ - TableCell(child: Text('Size').padding(right: 16)), - TableCell( - child: Row( - children: [ - Text(data.size.formatBytes()), - const Gap(12), - Text('${data.size} Bytes', style: GoogleFonts.robotoMono()).opacity(0.75), - ], - )), - ], - ), - TableRow( - children: [ - TableCell(child: Text('Name').padding(right: 16)), - TableCell(child: Text(data.name)), - ], - ), - if (data.hash.isNotEmpty) + child: SingleChildScrollView( + child: Table( + columnWidths: { + 0: IntrinsicColumnWidth(), + 1: FlexColumnWidth(), + }, + children: [ TableRow( children: [ - TableCell(child: Text('Hash').padding(right: 16)), - TableCell(child: Text(data.hash, style: GoogleFonts.robotoMono(fontSize: 11)).opacity(0.9)), + TableCell( + child: Text('attachmentUploadBy').tr().padding(right: 16), + ), + TableCell( + child: Row( + children: [ + if (data.accountId > 0) + AccountImage( + content: account?.avatar, + radius: 8, + ), + const Gap(8), + Text(data.accountId > 0 ? account?.nick ?? 'unknown'.tr() : 'unknown'.tr()), + const Gap(8), + Text('#${data.accountId}', style: GoogleFonts.robotoMono()).opacity(0.75), + ], + ), + ), ], ), - tableGap, - ...(data.metadata['exif']?.keys.map((k) => TableRow( + tableGap, + TableRow( + children: [ + TableCell(child: Text('Mimetype').padding(right: 16)), + TableCell(child: Text(data.mimetype)), + ], + ), + TableRow( + children: [ + TableCell(child: Text('Size').padding(right: 16)), + TableCell( + child: Row( + children: [ + Text(data.size.formatBytes()), + const Gap(12), + Text('${data.size} Bytes', style: GoogleFonts.robotoMono()).opacity(0.75), + ], + )), + ], + ), + TableRow( + children: [ + TableCell(child: Text('Name').padding(right: 16)), + TableCell(child: Text(data.name)), + ], + ), + if (data.hash.isNotEmpty) + TableRow( children: [ - TableCell(child: Text(k).padding(right: 16)), - TableCell(child: Text(data.metadata['exif'][k].toString())), + TableCell(child: Text('Hash').padding(right: 16)), + TableCell(child: Text(data.hash, style: GoogleFonts.robotoMono(fontSize: 11)).opacity(0.9)), ], - )) ?? - []), - ], - ).padding(horizontal: 20, vertical: 8), + ), + tableGap, + ...(data.metadata['exif']?.keys.map((k) => TableRow( + children: [ + TableCell(child: Text(k).padding(right: 16)), + TableCell(child: Text(data.metadata['exif'][k].toString())), + ], + )) ?? + []), + ], + ).padding(horizontal: 20, vertical: 8), + ), ), ], ), diff --git a/lib/widgets/link_preview.dart b/lib/widgets/link_preview.dart index cc092df..1cbad6a 100644 --- a/lib/widgets/link_preview.dart +++ b/lib/widgets/link_preview.dart @@ -94,11 +94,14 @@ class _LinkPreviewEntry extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.center, children: [ if (meta.icon?.isNotEmpty ?? false) - StyledWidget( - meta.icon!.endsWith('.svg') - ? SvgPicture.network(meta.icon!) + SizedBox( + width: 36, + height: 36, + child: meta.icon!.endsWith('.svg') + ? SvgPicture.network(meta.icon!, width: 36, height: 36) : UniversalImage( meta.icon!, + noErrorWidget: true, width: 36, height: 36, cacheHeight: 36, diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 137e14f..02853bb 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -256,9 +256,8 @@ class PostItem extends StatelessWidget { AttachmentList( data: displayableAttachments!, bordered: true, - gridded: true, maxHeight: showFullPost ? null : 480, - minWidth: 640, + maxWidth: MediaQuery.of(context).size.width - 20, fit: showFullPost ? BoxFit.cover : BoxFit.contain, padding: const EdgeInsets.symmetric(horizontal: 12), ),