From 0fdb1e4ead81f84908440b92bbb316c6eeb85a70 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 23 Sep 2024 23:19:52 +0800 Subject: [PATCH] :dizzy: Improve loading image animation --- lib/widgets/auto_cache_image.dart | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/widgets/auto_cache_image.dart b/lib/widgets/auto_cache_image.dart index c8e9697..f478ee0 100644 --- a/lib/widgets/auto_cache_image.dart +++ b/lib/widgets/auto_cache_image.dart @@ -34,8 +34,17 @@ class AutoCacheImage extends StatelessWidget { progressIndicatorBuilder: noProgressIndicator ? null : (context, url, downloadProgress) => Center( - child: CircularProgressIndicator( - value: downloadProgress.progress, + child: TweenAnimationBuilder( + 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 @@ -74,11 +83,20 @@ class AutoCacheImage extends StatelessWidget { ImageChunkEvent? loadingProgress) { if (loadingProgress == null) return child; return Center( - child: CircularProgressIndicator( - value: loadingProgress.expectedTotalBytes != null - ? loadingProgress.cumulativeBytesLoaded / - loadingProgress.expectedTotalBytes! - : null, + child: TweenAnimationBuilder( + tween: Tween( + begin: 0, + end: loadingProgress.expectedTotalBytes != null + ? loadingProgress.cumulativeBytesLoaded / + loadingProgress.expectedTotalBytes! + : 0, + ), + duration: const Duration(milliseconds: 300), + builder: (context, value, _) => CircularProgressIndicator( + value: loadingProgress.expectedTotalBytes != null + ? value.toDouble() + : null, + ), ), ); },