chore: Follow up image rendering

pull/953/head
krille-chan 2 years ago
parent 449357b501
commit 45e1122648
No known key found for this signature in database

@ -152,7 +152,8 @@ class ChatController extends State<ChatPageWithRoom>
return MatrixFile( return MatrixFile(
bytes: await xfile.readAsBytes(), bytes: await xfile.readAsBytes(),
name: xfile.name, name: xfile.name,
); mimeType: xfile.mimeType,
).detectFileType;
}, },
), ),
); );

@ -112,13 +112,15 @@ class MessageContent extends StatelessWidget {
const maxSize = 256.0; const maxSize = 256.0;
final w = event.content final w = event.content
.tryGetMap<String, Object?>('info') .tryGetMap<String, Object?>('info')
?.tryGet<int>('w') ?? ?.tryGet<int>('w');
maxSize;
final h = event.content final h = event.content
.tryGetMap<String, Object?>('info') .tryGetMap<String, Object?>('info')
?.tryGet<int>('h') ?? ?.tryGet<int>('h');
maxSize; var width = maxSize;
double width, height; var height = maxSize;
var fit = BoxFit.cover;
if (w != null && h != null) {
fit = BoxFit.contain;
if (w > h) { if (w > h) {
width = maxSize; width = maxSize;
height = max(32, maxSize * (h / w)); height = max(32, maxSize * (h / w));
@ -126,11 +128,12 @@ class MessageContent extends StatelessWidget {
height = maxSize; height = maxSize;
width = max(32, maxSize * (w / h)); width = max(32, maxSize * (w / h));
} }
}
return ImageBubble( return ImageBubble(
event, event,
width: width, width: width,
height: height, height: height,
fit: BoxFit.contain, fit: fit,
borderRadius: borderRadius, borderRadius: borderRadius,
); );
case CuteEventContent.eventType: case CuteEventContent.eventType:

@ -9,6 +9,7 @@ import 'package:pasteboard/pasteboard.dart';
import 'package:slugify/slugify.dart'; import 'package:slugify/slugify.dart';
import 'package:fluffychat/config/app_config.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/utils/platform_infos.dart';
import 'package:fluffychat/widgets/mxc_image.dart'; import 'package:fluffychat/widgets/mxc_image.dart';
import '../../widgets/avatar.dart'; import '../../widgets/avatar.dart';
@ -464,7 +465,7 @@ class InputBar extends StatelessWidget {
mimeType: content.mimeType, mimeType: content.mimeType,
bytes: data, bytes: data,
name: content.uri.split('/').last, name: content.uri.split('/').last,
); ).detectFileType;
room.sendFileEvent(file, shrinkImageMaxDimension: 1600); room.sendFileEvent(file, shrinkImageMaxDimension: 1600);
}, },
), ),

@ -34,6 +34,7 @@ class _BlurHashState extends State<BlurHash> {
} }
Future<Uint8List?> _computeBlurhashData() async { Future<Uint8List?> _computeBlurhashData() async {
if (_data != null) return _data!;
final ratio = widget.width / widget.height; final ratio = widget.width / widget.height;
var width = 32; var width = 32;
var height = 32; var height = 32;
@ -57,13 +58,14 @@ class _BlurHashState extends State<BlurHash> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Uint8List?>( return FutureBuilder<Uint8List?>(
future: _computeBlurhashData(), future: _computeBlurhashData(),
initialData: _data,
builder: (context, snapshot) { builder: (context, snapshot) {
final data = snapshot.data; final data = snapshot.data;
if (data == null) { if (data == null) {
return Container( return Container(
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.onInverseSurface,
); );
} }
return Image.memory( return Image.memory(

@ -130,11 +130,8 @@ class _MxcImageState extends State<MxcImage> {
} }
} }
bool _hasDataFromBeginning = false;
void _tryLoad(_) async { void _tryLoad(_) async {
if (_imageData != null) { if (_imageData != null) {
_hasDataFromBeginning = true;
return; return;
} }
try { try {
@ -163,22 +160,19 @@ class _MxcImageState extends State<MxcImage> {
final data = _imageData; final data = _imageData;
final hasData = data != null && data.isNotEmpty; final hasData = data != null && data.isNotEmpty;
return Stack( return AnimatedCrossFade(
children: [ crossFadeState:
if (!_hasDataFromBeginning) placeholder(context), hasData ? CrossFadeState.showSecond : CrossFadeState.showFirst,
AnimatedOpacity(
opacity: hasData ? 1 : 0,
duration: FluffyThemes.animationDuration, duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve, firstChild: placeholder(context),
child: hasData secondChild: hasData
? Image.memory( ? Image.memory(
data, data,
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
fit: widget.fit, fit: widget.fit,
filterQuality: widget.isThumbnail filterQuality:
? FilterQuality.low widget.isThumbnail ? FilterQuality.low : FilterQuality.medium,
: FilterQuality.medium,
errorBuilder: (context, __, ___) { errorBuilder: (context, __, ___) {
_isCached = false; _isCached = false;
_imageData = null; _imageData = null;
@ -190,8 +184,6 @@ class _MxcImageState extends State<MxcImage> {
width: widget.width, width: widget.width,
height: widget.height, height: widget.height,
), ),
),
],
); );
} }
} }

Loading…
Cancel
Save