💄 Optimize attachment list width in post

This commit is contained in:
LittleSheep 2024-12-29 22:34:17 +08:00
parent 5c7929e618
commit e236b7f98b
2 changed files with 33 additions and 33 deletions

View File

@ -18,6 +18,7 @@ class AttachmentList extends StatefulWidget {
final bool noGrow; final bool noGrow;
final BoxFit fit; final BoxFit fit;
final double? maxHeight; final double? maxHeight;
final double? minWidth;
final EdgeInsets? padding; final EdgeInsets? padding;
const AttachmentList({ const AttachmentList({
@ -28,6 +29,7 @@ class AttachmentList extends StatefulWidget {
this.noGrow = false, this.noGrow = false,
this.fit = BoxFit.cover, this.fit = BoxFit.cover,
this.maxHeight, this.maxHeight,
this.minWidth,
this.padding, this.padding,
}); });
@ -51,7 +53,7 @@ class _AttachmentListState extends State<AttachmentList> {
widget.bordered ? BorderSide(width: 1, color: Theme.of(context).dividerColor) : BorderSide.none; widget.bordered ? BorderSide(width: 1, color: Theme.of(context).dividerColor) : BorderSide.none;
final backgroundColor = Theme.of(context).colorScheme.surfaceContainer; final backgroundColor = Theme.of(context).colorScheme.surfaceContainer;
final constraints = BoxConstraints( final constraints = BoxConstraints(
minWidth: 80, minWidth: widget.minWidth ?? 80,
maxHeight: widget.maxHeight ?? MediaQuery.of(context).size.height, maxHeight: widget.maxHeight ?? MediaQuery.of(context).size.height,
); );
@ -67,42 +69,38 @@ class _AttachmentListState extends State<AttachmentList> {
return Container( return Container(
padding: widget.padding ?? EdgeInsets.zero, padding: widget.padding ?? EdgeInsets.zero,
constraints: BoxConstraints(maxHeight: constraints.maxHeight), constraints: constraints,
child: Container( child: GestureDetector(
constraints: constraints, child: AspectRatio(
width: double.infinity, aspectRatio: singleAspectRatio,
child: GestureDetector( child: Container(
child: AspectRatio( decoration: BoxDecoration(
aspectRatio: singleAspectRatio, color: backgroundColor,
child: Container( border: Border.fromBorderSide(borderSide),
decoration: BoxDecoration( borderRadius: AttachmentList.kDefaultRadius,
color: backgroundColor, ),
border: Border.fromBorderSide(borderSide), child: ClipRRect(
borderRadius: AttachmentList.kDefaultRadius, borderRadius: AttachmentList.kDefaultRadius,
), child: AttachmentItem(
child: ClipRRect( data: widget.data[0],
borderRadius: AttachmentList.kDefaultRadius, heroTag: heroTags[0],
child: AttachmentItem( fit: widget.fit,
data: widget.data[0],
heroTag: heroTags[0],
fit: widget.fit,
),
), ),
), ),
), ),
onTap: () {
if (widget.data.firstOrNull?.mediaType != SnMediaType.image) return;
context.pushTransparentRoute(
AttachmentZoomView(
data: widget.data.where((ele) => ele != null).cast(),
initialIndex: 0,
heroTags: heroTags,
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
), ),
onTap: () {
if (widget.data.firstOrNull?.mediaType != SnMediaType.image) return;
context.pushTransparentRoute(
AttachmentZoomView(
data: widget.data.where((ele) => ele != null).cast(),
initialIndex: 0,
heroTags: heroTags,
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
), ),
); );
} }

View File

@ -253,6 +253,7 @@ class PostItem extends StatelessWidget {
bordered: true, bordered: true,
gridded: true, gridded: true,
maxHeight: showFullPost ? null : 480, maxHeight: showFullPost ? null : 480,
minWidth: 640,
fit: showFullPost ? BoxFit.cover : BoxFit.contain, fit: showFullPost ? BoxFit.cover : BoxFit.contain,
padding: const EdgeInsets.symmetric(horizontal: 12), padding: const EdgeInsets.symmetric(horizontal: 12),
), ),
@ -930,6 +931,7 @@ class _PostQuoteContent extends StatelessWidget {
child: AttachmentList( child: AttachmentList(
data: child.preload!.attachments!, data: child.preload!.attachments!,
maxHeight: 360, maxHeight: 360,
minWidth: 640,
fit: BoxFit.contain, fit: BoxFit.contain,
gridded: true, gridded: true,
padding: const EdgeInsets.symmetric(horizontal: 12), padding: const EdgeInsets.symmetric(horizontal: 12),