Improve thumbnail

This commit is contained in:
2025-01-23 19:08:38 +08:00
parent 312e991935
commit 3ae5c7c7f2
2 changed files with 40 additions and 34 deletions

View File

@@ -277,17 +277,19 @@ class _AnimatedImageState extends State<AnimatedImage>
if (_imageInfo != null) {
if (widget.part != null) {
return CustomPaint(
result = CustomPaint(
isComplex: true,
painter: ImagePainter(
image: _imageInfo!.image,
part: widget.part!,
fit: widget.fit ?? BoxFit.cover,
),
child: SizedBox(
width: widget.width,
height: widget.height,
),
);
}
} else {
result = RawImage(
image: _imageInfo?.image,
width: widget.width,
@@ -306,6 +308,7 @@ class _AnimatedImageState extends State<AnimatedImage>
isAntiAlias: widget.isAntiAlias,
filterQuality: widget.filterQuality,
);
}
} else if (_lastException != null) {
result = const Center(
child: Icon(Icons.error),
@@ -362,10 +365,13 @@ class ImagePainter extends CustomPainter {
final ImagePart part;
final BoxFit fit;
/// Render a part of the image.
const ImagePainter({
required this.image,
this.part = const ImagePart(),
this.fit = BoxFit.cover,
});
@override
@@ -377,7 +383,8 @@ class ImagePainter extends CustomPainter {
part.y2 ?? image.height.toDouble(),
),
);
final Rect dst = Offset.zero & size;
var fitted = applyBoxFit(fit, Size(src.width, src.height), size).destination;
var dst = Alignment.center.inscribe(fitted, Offset.zero & size);
canvas.drawImageRect(image, src, dst, Paint());
}

View File

@@ -1283,7 +1283,9 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
y2 = double.parse(r.split('-')[1]);
}
}
} finally {}
} catch (_) {
// ignore
}
part = ImagePart(x1: x1, y1: y1, x2: x2, y2: y2);
}
return Padding(
@@ -1308,9 +1310,7 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
),
width: double.infinity,
height: double.infinity,
child: ClipRRect(
borderRadius:
const BorderRadius.all(Radius.circular(16)),
clipBehavior: Clip.antiAlias,
child: AnimatedImage(
image: CachedImageProvider(
url,
@@ -1324,7 +1324,6 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
),
),
),
),
const SizedBox(
height: 4,
),
@@ -1336,7 +1335,7 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
),
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
childAspectRatio: 0.65,
childAspectRatio: 0.7,
),
),
if (error != null)