chore: Follow up image rendering
This commit is contained in:
parent
449357b501
commit
45e1122648
5 changed files with 48 additions and 49 deletions
|
|
@ -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;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -111,26 +111,29 @@ class MessageContent extends StatelessWidget {
|
||||||
if (event.redacted) continue textmessage;
|
if (event.redacted) continue textmessage;
|
||||||
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;
|
||||||
if (w > h) {
|
var fit = BoxFit.cover;
|
||||||
width = maxSize;
|
if (w != null && h != null) {
|
||||||
height = max(32, maxSize * (h / w));
|
fit = BoxFit.contain;
|
||||||
} else {
|
if (w > h) {
|
||||||
height = maxSize;
|
width = maxSize;
|
||||||
width = max(32, maxSize * (w / h));
|
height = max(32, maxSize * (h / w));
|
||||||
|
} else {
|
||||||
|
height = maxSize;
|
||||||
|
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,35 +160,30 @@ 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(
|
duration: FluffyThemes.animationDuration,
|
||||||
opacity: hasData ? 1 : 0,
|
firstChild: placeholder(context),
|
||||||
duration: FluffyThemes.animationDuration,
|
secondChild: hasData
|
||||||
curve: FluffyThemes.animationCurve,
|
? Image.memory(
|
||||||
child: hasData
|
data,
|
||||||
? Image.memory(
|
width: widget.width,
|
||||||
data,
|
height: widget.height,
|
||||||
width: widget.width,
|
fit: widget.fit,
|
||||||
height: widget.height,
|
filterQuality:
|
||||||
fit: widget.fit,
|
widget.isThumbnail ? FilterQuality.low : FilterQuality.medium,
|
||||||
filterQuality: widget.isThumbnail
|
errorBuilder: (context, __, ___) {
|
||||||
? FilterQuality.low
|
_isCached = false;
|
||||||
: FilterQuality.medium,
|
_imageData = null;
|
||||||
errorBuilder: (context, __, ___) {
|
WidgetsBinding.instance.addPostFrameCallback(_tryLoad);
|
||||||
_isCached = false;
|
return placeholder(context);
|
||||||
_imageData = null;
|
},
|
||||||
WidgetsBinding.instance.addPostFrameCallback(_tryLoad);
|
)
|
||||||
return placeholder(context);
|
: SizedBox(
|
||||||
},
|
width: widget.width,
|
||||||
)
|
height: widget.height,
|
||||||
: SizedBox(
|
),
|
||||||
width: widget.width,
|
|
||||||
height: widget.height,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue