From 51c92fe6ed34d7b1304b060c124543aaa656ca46 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 6 Oct 2021 16:45:30 +0900 Subject: [PATCH] #94 paint color background during thumbnail hero --- lib/widgets/common/fx/transition_image.dart | 9 ++++++++- lib/widgets/common/thumbnail/image.dart | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/widgets/common/fx/transition_image.dart b/lib/widgets/common/fx/transition_image.dart index 01598fbe2..c530607db 100644 --- a/lib/widgets/common/fx/transition_image.dart +++ b/lib/widgets/common/fx/transition_image.dart @@ -13,6 +13,7 @@ class TransitionImage extends StatefulWidget { final double? width, height; final ValueListenable animation; final bool gaplessPlayback = false; + final Color? background; const TransitionImage({ Key? key, @@ -20,6 +21,7 @@ class TransitionImage extends StatefulWidget { required this.animation, this.width, this.height, + this.background, }) : super(key: key); @override @@ -136,10 +138,10 @@ class _TransitionImageState extends State { valueListenable: widget.animation, builder: (context, t, child) => CustomPaint( painter: _TransitionImagePainter( - // AssetImage(name).resolve(configuration) image: _imageInfo?.image, scale: _imageInfo?.scale ?? 1.0, t: t, + background: widget.background, ), ), ); @@ -150,11 +152,13 @@ class _TransitionImagePainter extends CustomPainter { final ui.Image? image; final double scale; final double t; + final Color? background; const _TransitionImagePainter({ required this.image, required this.scale, required this.t, + this.background, }); @override @@ -185,6 +189,9 @@ class _TransitionImagePainter extends CustomPainter { sourceSize, Offset.zero & inputSize, ); + if (background != null) { + canvas.drawRect(destinationRect, Paint()..color = background!); + } canvas.drawImageRect(image!, sourceRect, destinationRect, paint); } diff --git a/lib/widgets/common/thumbnail/image.dart b/lib/widgets/common/thumbnail/image.dart index ed3461e1c..26af6f3d8 100644 --- a/lib/widgets/common/thumbnail/image.dart +++ b/lib/widgets/common/thumbnail/image.dart @@ -232,12 +232,15 @@ class _ThumbnailImageState extends State { ); if (animate && widget.heroTag != null) { + final background = settings.imageBackground; + final backgroundColor = background.isColor? background.color : null; image = Hero( tag: widget.heroTag!, flightShuttleBuilder: (flight, animation, direction, fromHero, toHero) { return TransitionImage( image: entry.bestCachedThumbnail, animation: animation, + background: backgroundColor, ); }, transitionOnUserGestures: true,