mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 00:28:18 +08:00
fix imageview
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -12,28 +12,31 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class ImageModel {
|
class ImageModel {
|
||||||
ImageModel({
|
ImageModel({
|
||||||
required this.width,
|
required num? width,
|
||||||
required this.height,
|
required num? height,
|
||||||
required this.url,
|
required this.url,
|
||||||
this.liveUrl,
|
this.liveUrl,
|
||||||
});
|
}) {
|
||||||
|
this.width = width == null || width == 0 ? 1 : width;
|
||||||
|
this.height = height == null || height == 0 ? 1 : height;
|
||||||
|
}
|
||||||
|
|
||||||
dynamic width;
|
late num width;
|
||||||
dynamic height;
|
late num height;
|
||||||
String url;
|
String url;
|
||||||
String? liveUrl;
|
String? liveUrl;
|
||||||
bool? _isLongPic;
|
bool? _isLongPic;
|
||||||
bool? _isLivePhoto;
|
bool? _isLivePhoto;
|
||||||
|
|
||||||
dynamic get safeWidth => width ?? 1;
|
bool get isLongPic => _isLongPic ??= (height / width) > _maxRatio;
|
||||||
dynamic get safeHeight => height ?? 1;
|
|
||||||
bool get isLongPic => _isLongPic ??= (safeHeight / safeWidth) > (22 / 9);
|
|
||||||
bool get isLivePhoto =>
|
bool get isLivePhoto =>
|
||||||
_isLivePhoto ??= enableLivePhoto && liveUrl?.isNotEmpty == true;
|
_isLivePhoto ??= enableLivePhoto && liveUrl?.isNotEmpty == true;
|
||||||
|
|
||||||
static bool enableLivePhoto = Pref.enableLivePhoto;
|
static bool enableLivePhoto = Pref.enableLivePhoto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const double _maxRatio = 22 / 9;
|
||||||
|
|
||||||
Widget imageView(
|
Widget imageView(
|
||||||
double maxWidth,
|
double maxWidth,
|
||||||
List<ImageModel> picArr, {
|
List<ImageModel> picArr, {
|
||||||
@@ -44,17 +47,16 @@ Widget imageView(
|
|||||||
double imageWidth = (maxWidth - 2 * 5) / 3;
|
double imageWidth = (maxWidth - 2 * 5) / 3;
|
||||||
double imageHeight = imageWidth;
|
double imageHeight = imageWidth;
|
||||||
if (picArr.length == 1) {
|
if (picArr.length == 1) {
|
||||||
dynamic width = picArr[0].safeWidth;
|
dynamic width = picArr[0].width;
|
||||||
dynamic height = picArr[0].safeHeight;
|
dynamic height = picArr[0].height;
|
||||||
double ratioWH = width / height;
|
double ratioWH = width / height;
|
||||||
double ratioHW = height / width;
|
double ratioHW = height / width;
|
||||||
double maxRatio = 22 / 9;
|
|
||||||
imageWidth = ratioWH > 1.5
|
imageWidth = ratioWH > 1.5
|
||||||
? maxWidth
|
? maxWidth
|
||||||
: (ratioWH >= 1 || (height > width && ratioHW < 1.5))
|
: (ratioWH >= 1 || (height > width && ratioHW < 1.5))
|
||||||
? 2 * imageWidth
|
? 2 * imageWidth
|
||||||
: 1.5 * imageWidth;
|
: 1.5 * imageWidth;
|
||||||
imageHeight = imageWidth * min(ratioHW, maxRatio);
|
imageHeight = imageWidth * min(ratioHW, _maxRatio);
|
||||||
} else if (picArr.length == 2) {
|
} else if (picArr.length == 2) {
|
||||||
imageWidth = imageHeight = 2 * imageWidth;
|
imageWidth = imageHeight = 2 * imageWidth;
|
||||||
}
|
}
|
||||||
@@ -144,7 +146,7 @@ Widget imageView(
|
|||||||
width: imageWidth,
|
width: imageWidth,
|
||||||
height: imageHeight,
|
height: imageHeight,
|
||||||
isLongPic: () => item.isLongPic,
|
isLongPic: () => item.isLongPic,
|
||||||
callback: () => item.safeWidth <= item.safeHeight,
|
callback: () => item.width <= item.height,
|
||||||
getPlaceHolder: () {
|
getPlaceHolder: () {
|
||||||
return Container(
|
return Container(
|
||||||
width: imageWidth,
|
width: imageWidth,
|
||||||
|
|||||||
Reference in New Issue
Block a user