BorderRadiusTween.lerp supports null begin/end values (#79860)

This commit is contained in:
xubaolin
2021-04-17 08:24:02 +08:00
committed by GitHub
parent 7aa188bacc
commit aa7ab10822
3 changed files with 11 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ const double _kFrontClosedHeight = 92.0; // front layer height when closed
const double _kBackAppBarHeight = 56.0; // back layer (options) appbar height
// The size of the front layer heading's left and right beveled corners.
final Animatable<BorderRadius> _kFrontHeadingBevelRadius = BorderRadiusTween(
final Animatable<BorderRadius?> _kFrontHeadingBevelRadius = BorderRadiusTween(
begin: const BorderRadius.only(
topLeft: Radius.circular(12.0),
topRight: Radius.circular(12.0),
@@ -315,7 +315,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
color: Theme.of(context).canvasColor,
clipper: ShapeBorderClipper(
shape: BeveledRectangleBorder(
borderRadius: _kFrontHeadingBevelRadius.transform(_controller!.value),
borderRadius: _kFrontHeadingBevelRadius.transform(_controller!.value)!,
),
),
clipBehavior: Clip.antiAlias,

View File

@@ -125,7 +125,7 @@ class EdgeInsetsGeometryTween extends Tween<EdgeInsetsGeometry> {
/// [BorderRadius.lerp].
///
/// See [Tween] for a discussion on how to use interpolation objects.
class BorderRadiusTween extends Tween<BorderRadius> {
class BorderRadiusTween extends Tween<BorderRadius?> {
/// Creates a [BorderRadius] tween.
///
/// The [begin] and [end] properties may be null; the null value
@@ -134,7 +134,7 @@ class BorderRadiusTween extends Tween<BorderRadius> {
/// Returns the value this variable has at the given animation clock value.
@override
BorderRadius lerp(double t) => BorderRadius.lerp(begin, end, t)!;
BorderRadius? lerp(double t) => BorderRadius.lerp(begin, end, t);
}
/// An interpolation between two [Border]s.

View File

@@ -230,4 +230,11 @@ void main() {
expect(tween.transform(0.5), 0.31640625);
expect(tween.transform(1.0), 1.0);
});
test('BorderRadiusTween nullable test', () {
final BorderRadiusTween tween = BorderRadiusTween(begin: null, end: null);
expect(tween.transform(0.0), null);
expect(tween.transform(1.0), null);
expect(tween.lerp(0.0), null);
});
}