From f799900450f8e24b9a87579df5c544d881c8d75a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 31 Jul 2024 20:45:16 +0800 Subject: [PATCH] :bug: Fix crash on ratio 1 in attachment --- .../attachments/attachment_list_fullscreen.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/widgets/attachments/attachment_list_fullscreen.dart b/lib/widgets/attachments/attachment_list_fullscreen.dart index 62cec07..496f017 100644 --- a/lib/widgets/attachments/attachment_list_fullscreen.dart +++ b/lib/widgets/attachments/attachment_list_fullscreen.dart @@ -45,6 +45,14 @@ class _AttachmentListFullScreenState extends State { return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}'; } + double _getRatio() { + final value = widget.attachment.metadata?['ratio']; + if (value == null) return 1; + if (value is int) return value.toDouble(); + if (value is double) return value; + return 1; + } + @override void initState() { super.initState(); @@ -164,7 +172,7 @@ class _AttachmentListFullScreenState extends State { ), if (widget.attachment.metadata?['ratio'] != null) Text( - '${(widget.attachment.metadata?['ratio'] as double).toPrecision(2)}', + '${_getRatio().toPrecision(2)}', style: TextStyle( fontSize: 12, color: _unFocusColor,