🐛 Fix crash on ratio 1 in attachment

This commit is contained in:
LittleSheep 2024-07-31 20:45:16 +08:00
parent dfdf7b23c8
commit f799900450

View File

@ -45,6 +45,14 @@ class _AttachmentListFullScreenState extends State<AttachmentListFullScreen> {
return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}'; 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 @override
void initState() { void initState() {
super.initState(); super.initState();
@ -164,7 +172,7 @@ class _AttachmentListFullScreenState extends State<AttachmentListFullScreen> {
), ),
if (widget.attachment.metadata?['ratio'] != null) if (widget.attachment.metadata?['ratio'] != null)
Text( Text(
'${(widget.attachment.metadata?['ratio'] as double).toPrecision(2)}', '${_getRatio().toPrecision(2)}',
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12,
color: _unFocusColor, color: _unFocusColor,