Unverified Commit 0c24a4db authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `floatingActionButtonAnimator` not being updated (#110067)

parent 15b136d4
...@@ -1305,15 +1305,15 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr ...@@ -1305,15 +1305,15 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
@override @override
void didUpdateWidget(_FloatingActionButtonTransition oldWidget) { void didUpdateWidget(_FloatingActionButtonTransition oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (oldWidget.fabMotionAnimator != widget.fabMotionAnimator || oldWidget.fabMoveAnimation != widget.fabMoveAnimation) {
// Get the right scale and rotation animations to use for this widget.
_updateAnimations();
}
final bool oldChildIsNull = oldWidget.child == null; final bool oldChildIsNull = oldWidget.child == null;
final bool newChildIsNull = widget.child == null; final bool newChildIsNull = widget.child == null;
if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key) { if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key) {
return; return;
} }
if (oldWidget.fabMotionAnimator != widget.fabMotionAnimator || oldWidget.fabMoveAnimation != widget.fabMoveAnimation) {
// Get the right scale and rotation animations to use for this widget.
_updateAnimations();
}
if (_previousController.status == AnimationStatus.dismissed) { if (_previousController.status == AnimationStatus.dismissed) {
final double currentValue = widget.currentController.value; final double currentValue = widget.currentController.value;
if (currentValue == 0.0 || oldWidget.child == null) { if (currentValue == 0.0 || oldWidget.child == null) {
......
...@@ -607,6 +607,58 @@ void main() { ...@@ -607,6 +607,58 @@ void main() {
expect(tester.binding.transientCallbackCount, 0); expect(tester.binding.transientCallbackCount, 0);
}); });
testWidgets('Animator can be updated', (WidgetTester tester) async {
FloatingActionButtonAnimator fabAnimator = FloatingActionButtonAnimator.scaling;
FloatingActionButtonLocation fabLocation = FloatingActionButtonLocation.startFloat;
final Duration animationDuration = kFloatingActionButtonSegue * 2;
await tester.pumpWidget(_singleFabScaffold(
fabLocation,
animator: fabAnimator,
));
expect(find.byType(FloatingActionButton), findsOneWidget);
expect(tester.binding.transientCallbackCount, 0);
expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 44.0);
fabLocation = FloatingActionButtonLocation.endFloat;
await tester.pumpWidget(_singleFabScaffold(
fabLocation,
animator: fabAnimator,
));
expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, lessThan(16.0));
await tester.pump(animationDuration * 0.25);
expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, greaterThan(16));
await tester.pump(animationDuration * 0.25);
expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 756.0);
expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, lessThan(800 - 16));
await tester.pump(animationDuration * 0.25);
expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, lessThan(800 - 16));
await tester.pump(animationDuration * 0.25);
expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, equals(800 - 16));
fabLocation = FloatingActionButtonLocation.startFloat;
fabAnimator = _NoScalingFabAnimator();
await tester.pumpWidget(_singleFabScaffold(
fabLocation,
animator: fabAnimator,
));
await tester.pump(animationDuration * 0.25);
expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 756.0);
expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, equals(800 - 16));
await tester.pump(animationDuration * 0.25);
expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 44.0);
expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, lessThan(16.0));
});
}); });
group('Locations account for safe interactive areas', () { group('Locations account for safe interactive areas', () {
...@@ -1717,3 +1769,20 @@ class _LinearMovementFabAnimator extends FloatingActionButtonAnimator { ...@@ -1717,3 +1769,20 @@ class _LinearMovementFabAnimator extends FloatingActionButtonAnimator {
return const AlwaysStoppedAnimation<double>(1.0); return const AlwaysStoppedAnimation<double>(1.0);
} }
} }
class _NoScalingFabAnimator extends FloatingActionButtonAnimator {
@override
Offset getOffset({required Offset begin, required Offset end, required double progress}) {
return progress < 0.5 ? begin : end;
}
@override
Animation<double> getScaleAnimation({required Animation<double> parent}) {
return const AlwaysStoppedAnimation<double>(1.0);
}
@override
Animation<double> getRotationAnimation({required Animation<double> parent}) {
return const AlwaysStoppedAnimation<double>(1.0);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment