🐛 Fix attachment list NaN height

This commit is contained in:
LittleSheep 2024-12-29 14:03:19 +08:00
parent 7fbd4e9647
commit a6d4947a23
4 changed files with 16 additions and 16 deletions

View File

@ -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);

View File

@ -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<AttachmentList> {
(_) => const Uuid().v4(),
);
static const double kAttachmentMaxWidth = 640;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
@ -54,7 +52,7 @@ class _AttachmentListState extends State<AttachmentList> {
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<AttachmentList> {
.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<AttachmentList> {
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<AttachmentList> {
);
},
separatorBuilder: (context, index) => const Gap(8),
padding: widget.listPadding,
padding: widget.padding,
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
),

View File

@ -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),
],

View File

@ -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,