chore: Follow up image size
This commit is contained in:
parent
db747afb7b
commit
ba05050c2b
2 changed files with 20 additions and 24 deletions
|
|
@ -40,25 +40,13 @@ class ImageBubble extends StatelessWidget {
|
||||||
event.infoMap['xyz.amorgan.blurhash'] is String
|
event.infoMap['xyz.amorgan.blurhash'] is String
|
||||||
? event.infoMap['xyz.amorgan.blurhash']
|
? event.infoMap['xyz.amorgan.blurhash']
|
||||||
: 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
|
: '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(
|
return SizedBox(
|
||||||
width: this.width,
|
width: width,
|
||||||
height: this.height,
|
height: height,
|
||||||
child: BlurHash(
|
child: BlurHash(
|
||||||
hash: blurHashString,
|
hash: blurHashString,
|
||||||
decodingWidth: width,
|
decodingWidth: width?.round() ?? 64,
|
||||||
decodingHeight: height,
|
decodingHeight: height?.round() ?? 64,
|
||||||
imageFit: fit,
|
imageFit: fit,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
@ -106,22 +108,28 @@ class MessageContent extends StatelessWidget {
|
||||||
case EventTypes.Sticker:
|
case EventTypes.Sticker:
|
||||||
switch (event.messageType) {
|
switch (event.messageType) {
|
||||||
case MessageTypes.Image:
|
case MessageTypes.Image:
|
||||||
const width = 200;
|
const maxSize = 256.0;
|
||||||
const ratio = 2.0;
|
|
||||||
final w = event.content
|
final w = event.content
|
||||||
.tryGetMap<String, Object?>('info')
|
.tryGetMap<String, Object?>('info')
|
||||||
?.tryGet<int>('w') ??
|
?.tryGet<int>('w') ??
|
||||||
width;
|
maxSize;
|
||||||
final h = event.content
|
final h = event.content
|
||||||
.tryGetMap<String, Object?>('info')
|
.tryGetMap<String, Object?>('info')
|
||||||
?.tryGet<int>('h') ??
|
?.tryGet<int>('h') ??
|
||||||
width;
|
maxSize;
|
||||||
final overRatio = h > w * ratio;
|
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(
|
return ImageBubble(
|
||||||
event,
|
event,
|
||||||
height: overRatio ? width * ratio : null,
|
width: width,
|
||||||
width: width.toDouble(),
|
height: height,
|
||||||
fit: overRatio ? BoxFit.cover : BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
borderRadius: borderRadius,
|
borderRadius: borderRadius,
|
||||||
);
|
);
|
||||||
case MessageTypes.Sticker:
|
case MessageTypes.Sticker:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue