diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index aeb8f32d3..07745e8f3 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -152,7 +152,8 @@ class ChatController extends State return MatrixFile( bytes: await xfile.readAsBytes(), name: xfile.name, - ); + mimeType: xfile.mimeType, + ).detectFileType; }, ), ); diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 6c6d01c27..b495dd0d4 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -111,26 +111,29 @@ class MessageContent extends StatelessWidget { if (event.redacted) continue textmessage; const maxSize = 256.0; final w = event.content - .tryGetMap('info') - ?.tryGet('w') ?? - maxSize; + .tryGetMap('info') + ?.tryGet('w'); final h = event.content - .tryGetMap('info') - ?.tryGet('h') ?? - maxSize; - double width, height; - if (w > h) { - width = maxSize; - height = max(32, maxSize * (h / w)); - } else { - height = maxSize; - width = max(32, maxSize * (w / h)); + .tryGetMap('info') + ?.tryGet('h'); + var width = maxSize; + var height = maxSize; + var fit = BoxFit.cover; + if (w != null && h != null) { + fit = BoxFit.contain; + if (w > h) { + width = maxSize; + height = max(32, maxSize * (h / w)); + } else { + height = maxSize; + width = max(32, maxSize * (w / h)); + } } return ImageBubble( event, width: width, height: height, - fit: BoxFit.contain, + fit: fit, borderRadius: borderRadius, ); case CuteEventContent.eventType: diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 1140863e9..bcbf04d4a 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -9,6 +9,7 @@ import 'package:pasteboard/pasteboard.dart'; import 'package:slugify/slugify.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/mxc_image.dart'; import '../../widgets/avatar.dart'; @@ -464,7 +465,7 @@ class InputBar extends StatelessWidget { mimeType: content.mimeType, bytes: data, name: content.uri.split('/').last, - ); + ).detectFileType; room.sendFileEvent(file, shrinkImageMaxDimension: 1600); }, ), diff --git a/lib/widgets/blur_hash.dart b/lib/widgets/blur_hash.dart index 000cd275a..d4ad1dd47 100644 --- a/lib/widgets/blur_hash.dart +++ b/lib/widgets/blur_hash.dart @@ -34,6 +34,7 @@ class _BlurHashState extends State { } Future _computeBlurhashData() async { + if (_data != null) return _data!; final ratio = widget.width / widget.height; var width = 32; var height = 32; @@ -57,13 +58,14 @@ class _BlurHashState extends State { Widget build(BuildContext context) { return FutureBuilder( future: _computeBlurhashData(), + initialData: _data, builder: (context, snapshot) { final data = snapshot.data; if (data == null) { return Container( width: widget.width, height: widget.height, - color: Theme.of(context).colorScheme.surface, + color: Theme.of(context).colorScheme.onInverseSurface, ); } return Image.memory( diff --git a/lib/widgets/mxc_image.dart b/lib/widgets/mxc_image.dart index 55eb3e6ad..feea7dbaa 100644 --- a/lib/widgets/mxc_image.dart +++ b/lib/widgets/mxc_image.dart @@ -130,11 +130,8 @@ class _MxcImageState extends State { } } - bool _hasDataFromBeginning = false; - void _tryLoad(_) async { if (_imageData != null) { - _hasDataFromBeginning = true; return; } try { @@ -163,35 +160,30 @@ class _MxcImageState extends State { final data = _imageData; final hasData = data != null && data.isNotEmpty; - return Stack( - children: [ - if (!_hasDataFromBeginning) placeholder(context), - AnimatedOpacity( - opacity: hasData ? 1 : 0, - duration: FluffyThemes.animationDuration, - curve: FluffyThemes.animationCurve, - child: hasData - ? Image.memory( - data, - width: widget.width, - height: widget.height, - fit: widget.fit, - filterQuality: widget.isThumbnail - ? FilterQuality.low - : FilterQuality.medium, - errorBuilder: (context, __, ___) { - _isCached = false; - _imageData = null; - WidgetsBinding.instance.addPostFrameCallback(_tryLoad); - return placeholder(context); - }, - ) - : SizedBox( - width: widget.width, - height: widget.height, - ), - ), - ], + return AnimatedCrossFade( + crossFadeState: + hasData ? CrossFadeState.showSecond : CrossFadeState.showFirst, + duration: FluffyThemes.animationDuration, + firstChild: placeholder(context), + secondChild: hasData + ? Image.memory( + data, + width: widget.width, + height: widget.height, + fit: widget.fit, + filterQuality: + widget.isThumbnail ? FilterQuality.low : FilterQuality.medium, + errorBuilder: (context, __, ___) { + _isCached = false; + _imageData = null; + WidgetsBinding.instance.addPostFrameCallback(_tryLoad); + return placeholder(context); + }, + ) + : SizedBox( + width: widget.width, + height: widget.height, + ), ); } }