Skip to content

Commit

Permalink
fixes letsar#279
Browse files Browse the repository at this point in the history
  • Loading branch information
letsar committed Jul 10, 2022
1 parent e6772b7 commit b4e78de
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion lib/src/dismissal.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';

import 'controller.dart';
Expand Down Expand Up @@ -90,10 +92,65 @@ class _SlidableDismissalState extends State<SlidableDismissal>
}());
}

return SizeTransition(
return _SizeTransition(
sizeFactor: resizeAnimation,
axis: widget.axis,
child: widget.child,
);
}
}

/// We use a custom SizeTransition to not clip when the sizeFactor is 1.
class _SizeTransition extends AnimatedWidget {
/// Creates a size transition.
///
/// The [axis], [sizeFactor], and [axisAlignment] arguments must not be null.
/// The [axis] argument defaults to [Axis.vertical]. The [axisAlignment]
/// defaults to 0.0, which centers the child along the main axis during the
/// transition.
const _SizeTransition({
Key? key,
this.axis = Axis.vertical,
required Animation<double> sizeFactor,
this.child,
}) : super(key: key, listenable: sizeFactor);

/// [Axis.horizontal] if [sizeFactor] modifies the width, otherwise
/// [Axis.vertical].
final Axis axis;

/// The animation that controls the (clipped) size of the child.
///
/// The width or height (depending on the [axis] value) of this widget will be
/// its intrinsic width or height multiplied by [sizeFactor]'s value at the
/// current point in the animation.
///
/// If the value of [sizeFactor] is less than one, the child will be clipped
/// in the appropriate axis.
Animation<double> get sizeFactor => listenable as Animation<double>;

/// The widget below this widget in the tree.
///
/// {@macro flutter.widgets.ProxyWidget.child}
final Widget? child;

@override
Widget build(BuildContext context) {
final value = math.max<double>(sizeFactor.value, 0);
final AlignmentDirectional alignment;
if (axis == Axis.vertical) {
alignment = const AlignmentDirectional(-1, 0);
} else {
alignment = const AlignmentDirectional(0, -1);
}
return ClipRect(
clipBehavior: value == 1 ? Clip.none : Clip.hardEdge,
child: Align(
alignment: alignment,
heightFactor: axis == Axis.vertical ? value : null,
widthFactor: axis == Axis.horizontal ? value : null,
child: child,
),
);
}
}

0 comments on commit b4e78de

Please sign in to comment.