Skip to content

Commit

Permalink
fix: 评论区图片拉伸
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 25, 2024
1 parent 1393e02 commit 3bff0c8
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions lib/common/widgets/network_img_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,16 @@ class NetworkImgLayer extends StatelessWidget {
final String imageUrl =
'${src!.startsWith('//') ? 'https:${src!}' : src!}@${quality ?? 100}q.webp';
int? memCacheWidth, memCacheHeight;
double aspectRatio = (width / height).toDouble();

void setMemCacheSizes() {
if (aspectRatio > 1) {
memCacheHeight = height.cacheSize(context);
} else if (aspectRatio < 1) {
memCacheWidth = width.cacheSize(context);
} else {
if (origAspectRatio != null && origAspectRatio! > 1) {
memCacheWidth = width.cacheSize(context);
} else if (origAspectRatio != null && origAspectRatio! < 1) {
memCacheHeight = height.cacheSize(context);
} else {
memCacheWidth = width.cacheSize(context);
memCacheHeight = height.cacheSize(context);
}
}
}

setMemCacheSizes();

if (memCacheWidth == null && memCacheHeight == null) {
memCacheWidth = width.toInt();
if (width > height || (origAspectRatio != null && origAspectRatio! > 1)) {
memCacheWidth = width.cacheSize(context);
} else if (width < height ||
(origAspectRatio != null && origAspectRatio! < 1)) {
memCacheHeight = height.cacheSize(context);
} else {
// 不能同时设置,否则会导致图片变形
memCacheWidth = width.cacheSize(context);
// memCacheHeight = height.cacheSize(context);
}

return src != '' && src != null
Expand Down

0 comments on commit 3bff0c8

Please sign in to comment.