Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hot-fix: improve quality of thumbnail in chat and image picker #982

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/pages/chat/events/sending_image_info_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SendingImageInfoWidget extends StatelessWidget {
event.status == EventStatus.synced) {
sendingFileProgressNotifier.value = 1;
}
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;

return Hero(
tag: event.eventId,
Expand Down Expand Up @@ -102,10 +103,13 @@ class SendingImageInfoWidget extends StatelessWidget {
File(matrixFile.filePath!),
width: displayImageInfo.size.width,
height: displayImageInfo.size.height,
cacheHeight: displayImageInfo.size.height.toInt(),
cacheWidth: displayImageInfo.size.width.toInt(),
cacheHeight:
(displayImageInfo.size.height * devicePixelRatio)
.toInt(),
cacheWidth: (displayImageInfo.size.width * devicePixelRatio)
.toInt(),
fit: BoxFit.cover,
filterQuality: FilterQuality.medium,
filterQuality: FilterQuality.low,
),
],
),
Expand Down
24 changes: 14 additions & 10 deletions lib/widgets/mxc_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ class _MxcImageState extends State<MxcImage>
child: _ImageWidget(
filePath: filePath,
data: data,
width: widget.width,
height: widget.height,
width: widget.width ?? 256,
height: widget.height ?? 256,
fit: widget.fit,
needResize: needResize,
imageErrorWidgetBuilder: (context, __, ___) {
Expand All @@ -292,31 +292,33 @@ class _MxcImageState extends State<MxcImage>
class _ImageWidget extends StatelessWidget {
final String? filePath;
final Uint8List? data;
final double? width;
final double? height;
final double width;
final double height;
final bool needResize;
final BoxFit? fit;
final ImageErrorWidgetBuilder imageErrorWidgetBuilder;

const _ImageWidget({
this.filePath,
this.data,
this.width,
this.height,
required this.width,
required this.height,
required this.needResize,
this.fit,
required this.imageErrorWidgetBuilder,
});

@override
Widget build(BuildContext context) {
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
return filePath != null && filePath!.isNotEmpty
? Image.file(
File(filePath!),
width: width,
height: height,
cacheWidth: needResize ? width?.toInt() : null,
cacheHeight: needResize ? height?.toInt() : null,
cacheWidth: needResize ? (width * devicePixelRatio).toInt() : null,
cacheHeight:
needResize ? (height * devicePixelRatio).toInt() : null,
fit: fit,
filterQuality: FilterQuality.medium,
errorBuilder: imageErrorWidgetBuilder,
Expand All @@ -326,8 +328,10 @@ class _ImageWidget extends StatelessWidget {
data!,
width: width,
height: height,
cacheWidth: needResize ? width?.toInt() : null,
cacheHeight: needResize ? height?.toInt() : null,
cacheWidth:
needResize ? (width * devicePixelRatio).toInt() : null,
cacheHeight:
needResize ? (height * devicePixelRatio).toInt() : null,
fit: fit,
filterQuality: FilterQuality.medium,
errorBuilder: imageErrorWidgetBuilder,
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ packages:
description:
path: "."
ref: master
resolved-ref: f955d090935698a37fc08f6879b6afba8750e8c4
resolved-ref: a4695909775da036848874170b1618b4a5be0372
url: "[email protected]:linagora/linagora-design-flutter.git"
source: git
version: "0.0.1"
Expand Down Expand Up @@ -1904,10 +1904,10 @@ packages:
dependency: "direct main"
description:
name: photo_manager
sha256: b2d81bd197323697d1b335e2e04cea2f67e11624ced77cfd02917a10afaeba73
sha256: "2d698826421ebd045ecc0df60422e9dd24bd22b178310b68444385f783735b55"
url: "https://pub.dev"
source: hosted
version: "2.7.1"
version: "2.8.1"
pin_code_text_field:
dependency: "direct main"
description:
Expand Down