From ba05050c2bf052d71d1a23c377828cf71f9c59d3 Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 20 Mar 2024 16:15:18 +0100 Subject: [PATCH] chore: Follow up image size --- lib/pages/chat/events/image_bubble.dart | 20 ++++-------------- lib/pages/chat/events/message_content.dart | 24 ++++++++++++++-------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/pages/chat/events/image_bubble.dart b/lib/pages/chat/events/image_bubble.dart index 39a94763c..f043fcb0e 100644 --- a/lib/pages/chat/events/image_bubble.dart +++ b/lib/pages/chat/events/image_bubble.dart @@ -40,25 +40,13 @@ class ImageBubble extends StatelessWidget { event.infoMap['xyz.amorgan.blurhash'] is String ? event.infoMap['xyz.amorgan.blurhash'] : 'LEHV6nWB2yk8pyo0adR*.7kCMdnj'; - final ratio = event.infoMap['w'] is int && event.infoMap['h'] is int - ? event.infoMap['w'] / event.infoMap['h'] - : 1.0; - var width = 32; - var height = 32; - if (ratio > 1.0) { - height = (width / ratio).round(); - if (height <= 0) height = 1; - } else { - width = (height * ratio).round(); - if (width <= 0) width = 1; - } return SizedBox( - width: this.width, - height: this.height, + width: width, + height: height, child: BlurHash( hash: blurHashString, - decodingWidth: width, - decodingHeight: height, + decodingWidth: width?.round() ?? 64, + decodingHeight: height?.round() ?? 64, imageFit: fit, ), ); diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 8425ee35b..db6b44212 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -106,22 +108,28 @@ class MessageContent extends StatelessWidget { case EventTypes.Sticker: switch (event.messageType) { case MessageTypes.Image: - const width = 200; - const ratio = 2.0; + const maxSize = 256.0; final w = event.content .tryGetMap('info') ?.tryGet('w') ?? - width; + maxSize; final h = event.content .tryGetMap('info') ?.tryGet('h') ?? - width; - final overRatio = h > w * ratio; + maxSize; + double width, height; + if (w > h) { + width = maxSize; + height = max(32, maxSize * (h / w)); + } else { + height = maxSize; + width = max(32, maxSize * (w / h)); + } return ImageBubble( event, - height: overRatio ? width * ratio : null, - width: width.toDouble(), - fit: overRatio ? BoxFit.cover : BoxFit.contain, + width: width, + height: height, + fit: BoxFit.contain, borderRadius: borderRadius, ); case MessageTypes.Sticker: