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

View File

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