aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/common/fx
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/common/fx
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/widgets/common/fx')
-rw-r--r--lib/widgets/common/fx/blurred.dart94
-rw-r--r--lib/widgets/common/fx/borders.dart24
-rw-r--r--lib/widgets/common/fx/checkered_decoration.dart40
-rw-r--r--lib/widgets/common/fx/colors.dart26
-rw-r--r--lib/widgets/common/fx/dashed_path_painter.dart142
-rw-r--r--lib/widgets/common/fx/highlight_decoration.dart31
-rw-r--r--lib/widgets/common/fx/sweeper.dart157
-rw-r--r--lib/widgets/common/fx/transition_image.dart246
-rw-r--r--lib/widgets/common/fx/transitions.dart14
9 files changed, 774 insertions, 0 deletions
diff --git a/lib/widgets/common/fx/blurred.dart b/lib/widgets/common/fx/blurred.dart
new file mode 100644
index 0000000..f1e4139
--- /dev/null
+++ b/lib/widgets/common/fx/blurred.dart
@@ -0,0 +1,94 @@
+import 'dart:ui';
+
+import 'package:flutter/material.dart';
+
+final _filter = ImageFilter.blur(sigmaX: 4, sigmaY: 4);
+// do not use `ColorFilter.matrix` for identity,
+// as it yields performance issues when there are other layers on top
+final _identity = ImageFilter.matrix(Matrix4.identity().storage);
+
+class BlurredRect extends StatelessWidget {
+ final bool enabled;
+ final Widget child;
+
+ const BlurredRect({
+ super.key,
+ this.enabled = true,
+ required this.child,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return ClipRect(
+ // TODO TLAD [flutter vNext] use `BackdropFilter.grouped`
+ child: BackdropFilter(
+ // do not modify tree when disabling filter
+ filter: enabled ? _filter : _identity,
+ child: child,
+ ),
+ );
+ }
+}
+
+class BlurredRRect extends StatelessWidget {
+ final bool enabled;
+ final BorderRadius? borderRadius;
+ final Widget child;
+
+ const BlurredRRect({
+ super.key,
+ this.enabled = true,
+ required this.borderRadius,
+ required this.child,
+ });
+
+ factory BlurredRRect.all({
+ Key? key,
+ bool enabled = true,
+ required double borderRadius,
+ required Widget child,
+ }) {
+ return BlurredRRect(
+ key: key,
+ enabled: enabled,
+ borderRadius: BorderRadius.all(Radius.circular(borderRadius)),
+ child: child,
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ClipRRect(
+ borderRadius: borderRadius ?? BorderRadius.zero,
+ // TODO TLAD [flutter vNext] use `BackdropFilter.grouped`
+ child: BackdropFilter(
+ // do not modify tree when disabling filter
+ filter: enabled ? _filter : _identity,
+ child: child,
+ ),
+ );
+ }
+}
+
+class BlurredOval extends StatelessWidget {
+ final bool enabled;
+ final Widget child;
+
+ const BlurredOval({
+ super.key,
+ this.enabled = true,
+ required this.child,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return ClipOval(
+ // TODO TLAD [flutter vNext] use `BackdropFilter.grouped`
+ child: BackdropFilter(
+ // do not modify tree when disabling filter
+ filter: enabled ? _filter : _identity,
+ child: child,
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/common/fx/borders.dart b/lib/widgets/common/fx/borders.dart
new file mode 100644
index 0000000..ac4cfdc
--- /dev/null
+++ b/lib/widgets/common/fx/borders.dart
@@ -0,0 +1,24 @@
+import 'package:aves/widgets/common/extensions/theme.dart';
+import 'package:flutter/material.dart';
+
+class AvesBorder {
+ static Color _borderColor(BuildContext context) => Theme.of(context).isDark ? Colors.white30 : Colors.black26;
+
+ // 1 device pixel for straight lines is fine
+ static double straightBorderWidth(BuildContext context) => 1 / MediaQuery.devicePixelRatioOf(context);
+
+ // 1 device pixel for curves is too thin
+ static double curvedBorderWidth(BuildContext context) => MediaQuery.devicePixelRatioOf(context) > 2 ? 0.5 : 1.0;
+
+ static BorderSide straightSide(BuildContext context, {double? width}) => BorderSide(
+ color: _borderColor(context),
+ width: width ?? straightBorderWidth(context),
+ );
+
+ static BorderSide curvedSide(BuildContext context, {double? width}) => BorderSide(
+ color: _borderColor(context),
+ width: width ?? curvedBorderWidth(context),
+ );
+
+ static Border border(BuildContext context, {double? width}) => Border.fromBorderSide(curvedSide(context, width: width));
+}
diff --git a/lib/widgets/common/fx/checkered_decoration.dart b/lib/widgets/common/fx/checkered_decoration.dart
new file mode 100644
index 0000000..b7fb249
--- /dev/null
+++ b/lib/widgets/common/fx/checkered_decoration.dart
@@ -0,0 +1,40 @@
+import 'package:flutter/material.dart';
+
+class CheckeredPainter extends CustomPainter {
+ final Paint lightPaint, darkPaint;
+ final double checkSize;
+ final Offset offset;
+
+ CheckeredPainter({
+ Color light = const Color(0xFF999999),
+ Color dark = const Color(0xFF666666),
+ this.checkSize = 20,
+ this.offset = Offset.zero,
+ }) : lightPaint = Paint()..color = light,
+ darkPaint = Paint()..color = dark;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final background = Offset.zero & size;
+ canvas.drawRect(background, lightPaint);
+
+ final dx = offset.dx % (checkSize * 2);
+ final dy = offset.dy % (checkSize * 2);
+
+ final xMax = (size.width / checkSize).ceil();
+ final yMax = (size.height / checkSize).ceil();
+ for (var x = -2; x < xMax; x++) {
+ for (var y = -2; y < yMax; y++) {
+ if ((x + y) % 2 == 0) {
+ final check = Rect.fromLTWH(dx + x * checkSize, dy + y * checkSize, checkSize, checkSize);
+ if (check.overlaps(background)) {
+ canvas.drawRect(check.intersect(background), darkPaint);
+ }
+ }
+ }
+ }
+ }
+
+ @override
+ bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
+}
diff --git a/lib/widgets/common/fx/colors.dart b/lib/widgets/common/fx/colors.dart
new file mode 100644
index 0000000..0b7646f
--- /dev/null
+++ b/lib/widgets/common/fx/colors.dart
@@ -0,0 +1,26 @@
+import 'package:flutter/painting.dart';
+
+class MatrixColorFilters {
+ static const ColorFilter greyscale = ColorFilter.matrix(<double>[
+ 0.2126,
+ 0.7152,
+ 0.0722,
+ 0,
+ 0,
+ 0.2126,
+ 0.7152,
+ 0.0722,
+ 0,
+ 0,
+ 0.2126,
+ 0.7152,
+ 0.0722,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 0,
+ ]);
+}
diff --git a/lib/widgets/common/fx/dashed_path_painter.dart b/lib/widgets/common/fx/dashed_path_painter.dart
new file mode 100644
index 0000000..847ca42
--- /dev/null
+++ b/lib/widgets/common/fx/dashed_path_painter.dart
@@ -0,0 +1,142 @@
+import 'dart:math' as math;
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+
+// from https://stackoverflow.com/a/71099304/786656
+class DashedPathPainter extends CustomPainter {
+ final Path originalPath;
+ final Color pathColor;
+ final double strokeWidth;
+ final double dashGapLength;
+ final double dashLength;
+ late DashedPathProperties _dashedPathProperties;
+
+ DashedPathPainter({
+ required this.originalPath,
+ required this.pathColor,
+ this.strokeWidth = 3.0,
+ this.dashGapLength = 5.0,
+ this.dashLength = 10.0,
+ });
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ _dashedPathProperties = DashedPathProperties(
+ path: Path(),
+ dashLength: dashLength,
+ dashGapLength: dashGapLength,
+ );
+ final dashedPath = _getDashedPath(originalPath, dashLength, dashGapLength);
+ canvas.drawPath(
+ dashedPath,
+ Paint()
+ ..style = PaintingStyle.stroke
+ ..color = pathColor
+ ..strokeWidth = strokeWidth,
+ );
+ }
+
+ @override
+ bool shouldRepaint(DashedPathPainter oldDelegate) => oldDelegate.originalPath != originalPath || oldDelegate.pathColor != pathColor || oldDelegate.strokeWidth != strokeWidth || oldDelegate.dashGapLength != dashGapLength || oldDelegate.dashLength != dashLength;
+
+ Path _getDashedPath(
+ Path originalPath,
+ double dashLength,
+ double dashGapLength,
+ ) {
+ final metricsIterator = originalPath.computeMetrics().iterator;
+ while (metricsIterator.moveNext()) {
+ final metric = metricsIterator.current;
+ _dashedPathProperties.extractedPathLength = 0.0;
+ while (_dashedPathProperties.extractedPathLength < metric.length) {
+ if (_dashedPathProperties.addDashNext) {
+ _dashedPathProperties.addDash(metric, dashLength);
+ } else {
+ _dashedPathProperties.addDashGap(metric, dashGapLength);
+ }
+ }
+ }
+ return _dashedPathProperties.path;
+ }
+}
+
+class DashedPathProperties {
+ double extractedPathLength;
+ Path path;
+
+ final double _dashLength;
+ double _remainingDashLength;
+ double _remainingDashGapLength;
+ bool _previousWasDash;
+
+ DashedPathProperties({
+ required this.path,
+ required double dashLength,
+ required double dashGapLength,
+ }) : assert(dashLength > 0.0, 'dashLength must be > 0.0'),
+ assert(dashGapLength > 0.0, 'dashGapLength must be > 0.0'),
+ _dashLength = dashLength,
+ _remainingDashLength = dashLength,
+ _remainingDashGapLength = dashGapLength,
+ _previousWasDash = false,
+ extractedPathLength = 0.0;
+
+ bool get addDashNext {
+ if (!_previousWasDash || _remainingDashLength != _dashLength) {
+ return true;
+ }
+ return false;
+ }
+
+ void addDash(ui.PathMetric metric, double dashLength) {
+ // Calculate lengths (actual + available)
+ final end = _calculateLength(metric, _remainingDashLength);
+ final availableEnd = _calculateLength(metric, dashLength);
+ // Add path
+ final pathSegment = metric.extractPath(extractedPathLength, end);
+ path.addPath(pathSegment, Offset.zero);
+ // Update
+ final delta = _remainingDashLength - (end - extractedPathLength);
+ _remainingDashLength = _updateRemainingLength(
+ delta: delta,
+ end: end,
+ availableEnd: availableEnd,
+ initialLength: dashLength,
+ );
+ extractedPathLength = end;
+ _previousWasDash = true;
+ }
+
+ void addDashGap(ui.PathMetric metric, double dashGapLength) {
+ // Calculate lengths (actual + available)
+ final end = _calculateLength(metric, _remainingDashGapLength);
+ final availableEnd = _calculateLength(metric, dashGapLength);
+ // Move path's end point
+ ui.Tangent tangent = metric.getTangentForOffset(end)!;
+ path.moveTo(tangent.position.dx, tangent.position.dy);
+ // Update
+ final delta = end - extractedPathLength;
+ _remainingDashGapLength = _updateRemainingLength(
+ delta: delta,
+ end: end,
+ availableEnd: availableEnd,
+ initialLength: dashGapLength,
+ );
+ extractedPathLength = end;
+ _previousWasDash = false;
+ }
+
+ double _calculateLength(ui.PathMetric metric, double addedLength) {
+ return math.min(extractedPathLength + addedLength, metric.length);
+ }
+
+ double _updateRemainingLength({
+ required double delta,
+ required double end,
+ required double availableEnd,
+ required double initialLength,
+ }) {
+ return (delta > 0 && availableEnd == end) ? delta : initialLength;
+ }
+}
diff --git a/lib/widgets/common/fx/highlight_decoration.dart b/lib/widgets/common/fx/highlight_decoration.dart
new file mode 100644
index 0000000..f3a323a
--- /dev/null
+++ b/lib/widgets/common/fx/highlight_decoration.dart
@@ -0,0 +1,31 @@
+import 'package:flutter/material.dart';
+
+class HighlightDecoration extends Decoration {
+ final Color color;
+
+ const HighlightDecoration({required this.color});
+
+ @override
+ BoxPainter createBoxPainter([VoidCallback? onChanged]) {
+ return _HighlightDecorationPainter(this, onChanged);
+ }
+}
+
+class _HighlightDecorationPainter extends BoxPainter {
+ final HighlightDecoration decoration;
+
+ const _HighlightDecorationPainter(this.decoration, VoidCallback? onChanged) : super(onChanged);
+
+ @override
+ void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
+ final size = configuration.size;
+ if (size == null) return;
+
+ final confHeight = size.height;
+ final paintHeight = confHeight * .32;
+ final rect = Rect.fromLTWH(offset.dx, offset.dy + size.height * .58, size.width, paintHeight);
+ final rrect = RRect.fromRectAndRadius(rect, Radius.circular(paintHeight));
+ final paint = Paint()..color = decoration.color;
+ canvas.drawRRect(rrect, paint);
+ }
+}
diff --git a/lib/widgets/common/fx/sweeper.dart b/lib/widgets/common/fx/sweeper.dart
new file mode 100644
index 0000000..43e64d2
--- /dev/null
+++ b/lib/widgets/common/fx/sweeper.dart
@@ -0,0 +1,157 @@
+import 'dart:async';
+import 'dart:math';
+
+import 'package:aves/theme/durations.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+
+class Sweeper extends StatefulWidget {
+ final WidgetBuilder builder;
+ final double startAngle;
+ final double sweepAngle;
+ final Curve curve;
+ final ValueNotifier<bool> toggledNotifier;
+ final bool centerSweep;
+ final VoidCallback? onSweepEnd;
+
+ const Sweeper({
+ super.key,
+ required this.builder,
+ this.startAngle = -pi / 2,
+ this.sweepAngle = pi / 4,
+ this.curve = Curves.easeInOutCubic,
+ required this.toggledNotifier,
+ this.centerSweep = true,
+ this.onSweepEnd,
+ });
+
+ @override
+ State<Sweeper> createState() => _SweeperState();
+}
+
+class _SweeperState extends State<Sweeper> with SingleTickerProviderStateMixin {
+ late AnimationController _angleAnimationController;
+ late CurvedAnimation _angleAnimation;
+ late Animation<double> _angle;
+ bool _isAppearing = false;
+
+ bool get isToggled => widget.toggledNotifier.value;
+
+ @override
+ void initState() {
+ super.initState();
+ _angleAnimationController = AnimationController(
+ duration: ADurations.sweepingAnimation,
+ vsync: this,
+ );
+ final startAngle = widget.startAngle;
+ final sweepAngle = widget.sweepAngle;
+ final centerSweep = widget.centerSweep;
+ _angleAnimation = CurvedAnimation(
+ parent: _angleAnimationController,
+ curve: widget.curve,
+ );
+ _angle = Tween(
+ begin: startAngle - sweepAngle * (centerSweep ? .5 : 0),
+ end: startAngle + pi * 2 - sweepAngle * (centerSweep ? .5 : 1),
+ ).animate(_angleAnimation);
+ _angleAnimationController.addStatusListener(_onAnimationStatusChanged);
+ _registerWidget(widget);
+ }
+
+ @override
+ void didUpdateWidget(covariant Sweeper oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ _unregisterWidget(oldWidget);
+ _registerWidget(widget);
+ }
+
+ @override
+ void dispose() {
+ _angleAnimation.dispose();
+ _angleAnimationController.dispose();
+ _unregisterWidget(widget);
+ super.dispose();
+ }
+
+ void _registerWidget(Sweeper widget) {
+ widget.toggledNotifier.addListener(_onToggle);
+ }
+
+ void _unregisterWidget(Sweeper widget) {
+ widget.toggledNotifier.removeListener(_onToggle);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return IgnorePointer(
+ child: AnimatedOpacity(
+ opacity: isToggled && (_isAppearing || _angleAnimationController.status == AnimationStatus.forward) ? 1 : 0,
+ duration: ADurations.sweeperOpacityAnimation,
+ child: ValueListenableBuilder<double>(
+ valueListenable: _angleAnimationController,
+ builder: (context, value, child) {
+ return ClipPath(
+ clipper: _SweepClipPath(
+ startAngle: _angle.value,
+ sweepAngle: widget.sweepAngle,
+ ),
+ child: widget.builder(context),
+ );
+ }),
+ ),
+ );
+ }
+
+ void _onAnimationStatusChanged(AnimationStatus status) {
+ setState(() {});
+ if (status.isCompleted) {
+ widget.onSweepEnd?.call();
+ }
+ }
+
+ Future<void> _onToggle() async {
+ if (isToggled) {
+ _isAppearing = true;
+ setState(() {});
+ await Future.delayed(ADurations.sweeperOpacityAnimation * timeDilation);
+ _isAppearing = false;
+ if (!mounted) return;
+ _angleAnimationController.reset();
+ unawaited(_angleAnimationController.forward());
+ }
+ if (!mounted) return;
+ setState(() {});
+ }
+}
+
+class _SweepClipPath extends CustomClipper<Path> {
+ final double startAngle;
+ final double sweepAngle;
+
+ const _SweepClipPath({required this.startAngle, required this.sweepAngle});
+
+ @override
+ Path getClip(Size size) {
+ final width = size.width;
+ final height = size.height;
+ final centerX = width / 2;
+ final centerY = height / 2;
+ final diagonal = sqrt(width * width + height * height);
+ return Path()
+ ..moveTo(centerX, centerY)
+ ..addArc(
+ Rect.fromCenter(
+ center: Offset(centerX, centerY),
+ width: diagonal,
+ height: diagonal,
+ ),
+ startAngle,
+ sweepAngle,
+ )
+ ..lineTo(centerX, centerY);
+ }
+
+ @override
+ bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
+}
diff --git a/lib/widgets/common/fx/transition_image.dart b/lib/widgets/common/fx/transition_image.dart
new file mode 100644
index 0000000..044b708
--- /dev/null
+++ b/lib/widgets/common/fx/transition_image.dart
@@ -0,0 +1,246 @@
+import 'dart:ui' as ui;
+
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+
+// adapted from Flutter `_ImageState` in `/widgets/image.dart`
+// and `DecorationImagePainter` in `/painting/decoration_image.dart`
+// to transition between 2 different fits during hero animation:
+// - BoxFit.cover at t=0
+// - BoxFit.contain at t=1
+
+class TransitionImage extends StatefulWidget {
+ final ImageProvider image;
+ final ValueListenable<double> animation;
+ final BoxFit thumbnailFit, viewerFit;
+ final Color? background;
+
+ const TransitionImage({
+ super.key,
+ required this.image,
+ required this.animation,
+ required this.thumbnailFit,
+ required this.viewerFit,
+ this.background,
+ });
+
+ @override
+ State<TransitionImage> createState() => _TransitionImageState();
+}
+
+class _TransitionImageState extends State<TransitionImage> with WidgetsBindingObserver {
+ ImageStream? _imageStream;
+ ImageInfo? _imageInfo;
+ bool _isListeningToStream = false;
+ bool _wasSynchronouslyLoaded = false;
+ late DisposableBuildContext<State<TransitionImage>> _scrollAwareContext;
+ ImageStreamCompleterHandle? _completerHandle;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addObserver(this);
+ _scrollAwareContext = DisposableBuildContext<State<TransitionImage>>(this);
+ }
+
+ @override
+ void dispose() {
+ assert(_imageStream != null);
+ WidgetsBinding.instance.removeObserver(this);
+ _stopListeningToStream();
+ _completerHandle?.dispose();
+ _scrollAwareContext.dispose();
+ _replaceImage(info: null);
+ super.dispose();
+ }
+
+ @override
+ void didChangeDependencies() {
+ _resolveImage();
+
+ if (TickerMode.of(context)) {
+ _listenToStream();
+ } else {
+ _stopListeningToStream(keepStreamAlive: true);
+ }
+
+ super.didChangeDependencies();
+ }
+
+ @override
+ void didUpdateWidget(TransitionImage oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (widget.image != oldWidget.image) {
+ _resolveImage();
+ }
+ }
+
+ @override
+ void reassemble() {
+ _resolveImage(); // in case the image cache was flushed
+ super.reassemble();
+ }
+
+ void _resolveImage() {
+ final ScrollAwareImageProvider provider = ScrollAwareImageProvider<Object>(
+ context: _scrollAwareContext,
+ imageProvider: widget.image,
+ );
+ final ImageStream newStream = provider.resolve(createLocalImageConfiguration(context));
+ _updateSourceStream(newStream);
+ }
+
+ ImageStreamListener? _imageStreamListener;
+
+ ImageStreamListener _getListener({bool recreateListener = false}) {
+ if (_imageStreamListener == null || recreateListener) {
+ _imageStreamListener = ImageStreamListener(_handleImageFrame);
+ }
+ return _imageStreamListener!;
+ }
+
+ void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) {
+ setState(() {
+ _replaceImage(info: imageInfo);
+ _wasSynchronouslyLoaded = _wasSynchronouslyLoaded | synchronousCall;
+ });
+ }
+
+ void _replaceImage({required ImageInfo? info}) {
+ final ImageInfo? oldImageInfo = _imageInfo;
+ SchedulerBinding.instance.addPostFrameCallback((_) => oldImageInfo?.dispose());
+ _imageInfo = info;
+ }
+
+ // Updates _imageStream to newStream, and moves the stream listener
+ // registration from the old stream to the new stream (if a listener was
+ // registered).
+ void _updateSourceStream(ImageStream newStream) {
+ if (_imageStream?.key == newStream.key) {
+ return;
+ }
+
+ if (_isListeningToStream) {
+ _imageStream!.removeListener(_getListener());
+ }
+
+ setState(() {
+ _replaceImage(info: null);
+ _wasSynchronouslyLoaded = false;
+ });
+
+ _imageStream = newStream;
+ if (_isListeningToStream) {
+ _imageStream!.addListener(_getListener());
+ }
+ }
+
+ void _listenToStream() {
+ if (_isListeningToStream) {
+ return;
+ }
+
+ _imageStream!.addListener(_getListener());
+ _completerHandle?.dispose();
+ _completerHandle = null;
+
+ _isListeningToStream = true;
+ }
+
+ /// Stops listening to the image stream, if this state object has attached a
+ /// listener.
+ ///
+ /// If the listener from this state is the last listener on the stream, the
+ /// stream will be disposed. To keep the stream alive, set `keepStreamAlive`
+ /// to true, which create [ImageStreamCompleterHandle] to keep the completer
+ /// alive and is compatible with the [TickerMode] being off.
+ void _stopListeningToStream({bool keepStreamAlive = false}) {
+ if (!_isListeningToStream) {
+ return;
+ }
+
+ if (keepStreamAlive && _completerHandle == null && _imageStream?.completer != null) {
+ _completerHandle = _imageStream!.completer!.keepAlive();
+ }
+
+ _imageStream!.removeListener(_getListener());
+ _isListeningToStream = false;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ValueListenableBuilder<double>(
+ valueListenable: widget.animation,
+ builder: (context, t, child) => CustomPaint(
+ painter: _TransitionImagePainter(
+ image: _imageInfo?.image,
+ scale: _imageInfo?.scale ?? 1.0,
+ t: t,
+ thumbnailFit: widget.thumbnailFit,
+ viewerFit: widget.viewerFit,
+ background: widget.background,
+ ),
+ ),
+ );
+ }
+}
+
+class _TransitionImagePainter extends CustomPainter {
+ final ui.Image? image;
+ final double scale, t;
+ final Color? background;
+ final BoxFit thumbnailFit, viewerFit;
+
+ static final _paint = Paint()
+ ..isAntiAlias = false
+ ..filterQuality = FilterQuality.low;
+ static const _alignment = Alignment.center;
+
+ const _TransitionImagePainter({
+ required this.image,
+ required this.scale,
+ required this.t,
+ required this.thumbnailFit,
+ required this.viewerFit,
+ required this.background,
+ });
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final _image = image;
+ if (_image == null) return;
+
+ if (size.isEmpty) {
+ return;
+ }
+
+ final outputSize = size;
+ final inputSize = Size(_image.width.toDouble(), _image.height.toDouble());
+
+ final thumbnailSizes = applyBoxFit(thumbnailFit, inputSize / scale, size);
+ final viewerSizes = applyBoxFit(viewerFit, inputSize / scale, size);
+ final sourceSize = Size.lerp(thumbnailSizes.source, viewerSizes.source, t)! * scale;
+ final destinationSize = Size.lerp(thumbnailSizes.destination, viewerSizes.destination, t)!;
+
+ final halfWidthDelta = (outputSize.width - destinationSize.width) / 2.0;
+ final halfHeightDelta = (outputSize.height - destinationSize.height) / 2.0;
+ final dx = halfWidthDelta + _alignment.x * halfWidthDelta;
+ final dy = halfHeightDelta + _alignment.y * halfHeightDelta;
+ final destinationPosition = Offset(dx, dy);
+
+ final destinationRect = destinationPosition & destinationSize;
+ final sourceRect = _alignment.inscribe(
+ sourceSize,
+ Offset.zero & inputSize,
+ );
+ if (background != null) {
+ // deflate to avoid background artifact around opaque image
+ canvas.drawRect(destinationRect.deflate(1), Paint()..color = background!);
+ }
+ canvas.drawImageRect(_image, sourceRect, destinationRect, _paint);
+ }
+
+ @override
+ bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
+}
diff --git a/lib/widgets/common/fx/transitions.dart b/lib/widgets/common/fx/transitions.dart
new file mode 100644
index 0000000..b4b7f16
--- /dev/null
+++ b/lib/widgets/common/fx/transitions.dart
@@ -0,0 +1,14 @@
+import 'package:flutter/widgets.dart';
+
+class AvesTransitions {
+ static Widget formTransitionBuilder(Widget child, Animation<double> animation) {
+ return FadeTransition(
+ opacity: animation,
+ child: SizeTransition(
+ sizeFactor: animation,
+ axisAlignment: -1,
+ child: child,
+ ),
+ );
+ }
+}