💫 Improve loading image animation

This commit is contained in:
LittleSheep 2024-09-23 23:19:52 +08:00
parent 724bd6592e
commit 0fdb1e4ead

View File

@ -34,8 +34,17 @@ class AutoCacheImage extends StatelessWidget {
progressIndicatorBuilder: noProgressIndicator progressIndicatorBuilder: noProgressIndicator
? null ? null
: (context, url, downloadProgress) => Center( : (context, url, downloadProgress) => Center(
child: CircularProgressIndicator( child: TweenAnimationBuilder(
value: downloadProgress.progress, tween: Tween(
begin: 0,
end: downloadProgress.progress ?? 0,
),
duration: const Duration(milliseconds: 300),
builder: (context, value, _) => CircularProgressIndicator(
value: downloadProgress.progress != null
? value.toDouble()
: null,
),
), ),
), ),
errorWidget: noErrorWidget errorWidget: noErrorWidget
@ -74,11 +83,20 @@ class AutoCacheImage extends StatelessWidget {
ImageChunkEvent? loadingProgress) { ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child; if (loadingProgress == null) return child;
return Center( return Center(
child: CircularProgressIndicator( child: TweenAnimationBuilder(
value: loadingProgress.expectedTotalBytes != null tween: Tween(
? loadingProgress.cumulativeBytesLoaded / begin: 0,
loadingProgress.expectedTotalBytes! end: loadingProgress.expectedTotalBytes != null
: null, ? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: 0,
),
duration: const Duration(milliseconds: 300),
builder: (context, value, _) => CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? value.toDouble()
: null,
),
), ),
); );
}, },