From a6d4947a23d3dc07e86001b15b4b8f92870fb21b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 29 Dec 2024 14:03:19 +0800 Subject: [PATCH] :bug: Fix attachment list NaN height --- lib/controllers/post_write_controller.dart | 8 +++++--- lib/widgets/attachment/attachment_list.dart | 14 ++++++-------- lib/widgets/chat/chat_message.dart | 2 +- lib/widgets/post/post_item.dart | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/controllers/post_write_controller.dart b/lib/controllers/post_write_controller.dart index f3b5569..6949ce2 100644 --- a/lib/controllers/post_write_controller.dart +++ b/lib/controllers/post_write_controller.dart @@ -354,9 +354,11 @@ class PostWriteController extends ChangeNotifier { ); try { - final compressedAttachment = await _tryCompressVideoCopy(context, media); - if (compressedAttachment != null) { - item = await attach.updateOne(item, compressedId: compressedAttachment.id); + if (context.mounted) { + final compressedAttachment = await _tryCompressVideoCopy(context, media); + if (compressedAttachment != null) { + item = await attach.updateOne(item, compressedId: compressedAttachment.id); + } } } catch (err) { if (context.mounted) context.showErrorDialog(err); diff --git a/lib/widgets/attachment/attachment_list.dart b/lib/widgets/attachment/attachment_list.dart index 7b87457..d56973c 100644 --- a/lib/widgets/attachment/attachment_list.dart +++ b/lib/widgets/attachment/attachment_list.dart @@ -18,7 +18,7 @@ class AttachmentList extends StatefulWidget { final bool noGrow; final BoxFit fit; final double? maxHeight; - final EdgeInsets? listPadding; + final EdgeInsets? padding; const AttachmentList({ super.key, @@ -28,7 +28,7 @@ class AttachmentList extends StatefulWidget { this.noGrow = false, this.fit = BoxFit.cover, this.maxHeight, - this.listPadding, + this.padding, }); static const BorderRadius kDefaultRadius = BorderRadius.all(Radius.circular(8)); @@ -43,8 +43,6 @@ class _AttachmentListState extends State { (_) => const Uuid().v4(), ); - static const double kAttachmentMaxWidth = 640; - @override Widget build(BuildContext context) { return LayoutBuilder( @@ -54,7 +52,7 @@ class _AttachmentListState extends State { final backgroundColor = Theme.of(context).colorScheme.surfaceContainer; final constraints = BoxConstraints( minWidth: 80, - maxHeight: widget.maxHeight ?? double.infinity, + maxHeight: widget.maxHeight ?? MediaQuery.of(context).size.height, ); if (widget.data.isEmpty) return const SizedBox.shrink(); @@ -68,7 +66,7 @@ class _AttachmentListState extends State { .toDouble(); return Padding( - padding: widget.listPadding ?? EdgeInsets.zero, + padding: widget.padding ?? EdgeInsets.zero, child: Container( constraints: constraints, width: double.infinity, @@ -110,7 +108,7 @@ class _AttachmentListState extends State { if (widget.gridded) { return Padding( - padding: widget.listPadding ?? EdgeInsets.zero, + padding: widget.padding ?? EdgeInsets.zero, child: Container( decoration: BoxDecoration( color: backgroundColor, @@ -220,7 +218,7 @@ class _AttachmentListState extends State { ); }, separatorBuilder: (context, index) => const Gap(8), - padding: widget.listPadding, + padding: widget.padding, physics: const BouncingScrollPhysics(), scrollDirection: Axis.horizontal, ), diff --git a/lib/widgets/chat/chat_message.dart b/lib/widgets/chat/chat_message.dart index b55f512..5f2c0f9 100644 --- a/lib/widgets/chat/chat_message.dart +++ b/lib/widgets/chat/chat_message.dart @@ -162,7 +162,7 @@ class ChatMessage extends StatelessWidget { gridded: true, noGrow: true, maxHeight: 520, - listPadding: const EdgeInsets.only(top: 8), + padding: const EdgeInsets.only(top: 8), ), if (!hasMerged && !isCompact) const Gap(12) else if (!isCompact) const Gap(6), ], diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index 815cb0b..c3ffa82 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -254,7 +254,7 @@ class PostItem extends StatelessWidget { gridded: true, maxHeight: showFullPost ? null : 480, fit: showFullPost ? BoxFit.cover : BoxFit.contain, - listPadding: const EdgeInsets.symmetric(horizontal: 12), + padding: const EdgeInsets.symmetric(horizontal: 12), ), if (data.body['content'] != null) LinkPreviewWidget( @@ -336,10 +336,10 @@ class PostShareImageWidget extends StatelessWidget { isRelativeDate: false, ).padding(horizontal: 16, bottom: 8), if (data.type != 'article' && (data.preload?.attachments?.isNotEmpty ?? false)) - AttachmentList( + StyledWidget(AttachmentList( data: data.preload!.attachments!, gridded: true, - ).padding(horizontal: 16, bottom: 8), + )).padding(horizontal: 16, bottom: 8), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -932,7 +932,7 @@ class _PostQuoteContent extends StatelessWidget { maxHeight: 360, fit: BoxFit.contain, gridded: true, - listPadding: const EdgeInsets.symmetric(horizontal: 12), + padding: const EdgeInsets.symmetric(horizontal: 12), ), ).padding( top: 8,