forked from firka/flutter
Fix floatingActionButtonAnimator not being updated (#110067)
This commit is contained in:
@@ -1305,15 +1305,15 @@ class _FloatingActionButtonTransitionState extends State<_FloatingActionButtonTr
|
||||
@override
|
||||
void didUpdateWidget(_FloatingActionButtonTransition 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 newChildIsNull = widget.child == null;
|
||||
if (oldChildIsNull == newChildIsNull && oldWidget.child?.key == widget.child?.key) {
|
||||
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) {
|
||||
final double currentValue = widget.currentController.value;
|
||||
if (currentValue == 0.0 || oldWidget.child == null) {
|
||||
|
||||
@@ -607,6 +607,58 @@ void main() {
|
||||
|
||||
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', () {
|
||||
@@ -1717,3 +1769,20 @@ class _LinearMovementFabAnimator extends FloatingActionButtonAnimator {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user