Add an AlignTransition widget (#12724)
This commit is contained in:
parent
2b2b3ab516
commit
aff731c0a6
@ -443,6 +443,45 @@ class DecoratedBoxTransition extends AnimatedWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Animated version of an [Align] that animates its [Align.alignment] property.
|
||||
class AlignTransition extends AnimatedWidget {
|
||||
/// Creates an animated [Align] whose [AlignmentGeometry] animation updates
|
||||
/// the widget.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [new Align].
|
||||
const AlignTransition({
|
||||
Key key,
|
||||
@required Animation<AlignmentGeometry> alignment,
|
||||
@required this.child,
|
||||
this.widthFactor,
|
||||
this.heightFactor,
|
||||
}) : super(key: key, listenable: alignment);
|
||||
|
||||
/// The animation that controls the child's alignment.
|
||||
Animation<AlignmentGeometry> get alignment => listenable;
|
||||
|
||||
/// If non-null, the child's width factor, see [Align.widthFactor].
|
||||
final double widthFactor;
|
||||
|
||||
/// If non-null, the child's height factor, see [Align.heightFactor].
|
||||
final double heightFactor;
|
||||
|
||||
/// The widget below this widget in the tree.
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Align(
|
||||
alignment: alignment.value,
|
||||
widthFactor: widthFactor,
|
||||
heightFactor: heightFactor,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A builder that builds a widget given a child.
|
||||
///
|
||||
/// The child should typically be part of the returned widget tree.
|
||||
|
@ -146,4 +146,49 @@ void main() {
|
||||
expect(actualDecoration.boxShadow[0].color, const Color(0x66000000));
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('AlignTransition animates', (WidgetTester tester) async {
|
||||
final AnimationController controller = new AnimationController(vsync: const TestVSync());
|
||||
final Animation<Alignment> alignmentTween = new AlignmentTween(
|
||||
begin: const Alignment(-1.0, 0.0),
|
||||
end: const Alignment(1.0, 1.0),
|
||||
).animate(controller);
|
||||
final Widget widget = new AlignTransition(
|
||||
alignment: alignmentTween,
|
||||
child: const Text('Ready', textDirection: TextDirection.ltr),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(widget);
|
||||
|
||||
final RenderPositionedBox actualPositionedBox = tester.renderObject(find.byType(Align));
|
||||
|
||||
Alignment actualAlignment = actualPositionedBox.alignment;
|
||||
expect(actualAlignment, const Alignment(-1.0, 0.0));
|
||||
|
||||
controller.value = 0.5;
|
||||
await tester.pump();
|
||||
actualAlignment = actualPositionedBox.alignment;
|
||||
expect(actualAlignment, const Alignment(0.0, 0.5));
|
||||
});
|
||||
|
||||
testWidgets('AlignTransition keeps width and height factors', (WidgetTester tester) async {
|
||||
final AnimationController controller = new AnimationController(vsync: const TestVSync());
|
||||
final Animation<Alignment> alignmentTween = new AlignmentTween(
|
||||
begin: const Alignment(-1.0, 0.0),
|
||||
end: const Alignment(1.0, 1.0),
|
||||
).animate(controller);
|
||||
final Widget widget = new AlignTransition(
|
||||
alignment: alignmentTween,
|
||||
child: const Text('Ready', textDirection: TextDirection.ltr),
|
||||
widthFactor: 0.3,
|
||||
heightFactor: 0.4,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(widget);
|
||||
|
||||
final Align actualAlign = tester.widget(find.byType(Align));
|
||||
|
||||
expect(actualAlign.widthFactor, 0.3);
|
||||
expect(actualAlign.heightFactor, 0.4);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user