From 8469896c5a2348551c90ba4f4e74f885baad28ae Mon Sep 17 00:00:00 2001 From: xubaolin Date: Sat, 29 Oct 2022 01:24:58 +0800 Subject: [PATCH] Fix DDS do not support Curves.easeInOutBack curve (#114222) --- .../widgets/draggable_scrollable_sheet.dart | 17 +++++++----- .../draggable_scrollable_sheet_test.dart | 27 ++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart index c9c27cb277..7df9c4934d 100644 --- a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart +++ b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart @@ -136,13 +136,12 @@ class DraggableScrollableController extends ChangeNotifier { animationController.value, _attachedController!.position.context.notificationContext!, ); - if (animationController.value > _attachedController!.extent.maxSize || - animationController.value < _attachedController!.extent.minSize) { - // Animation hit the max or min size, stop animating. - animationController.stop(canceled: false); - } }); - await animationController.animateTo(size, duration: duration, curve: curve); + await animationController.animateTo( + clampDouble(size, _attachedController!.extent.minSize, _attachedController!.extent.maxSize), + duration: duration, + curve: curve, + ); } /// Jumps the attached sheet from its current size to the given [size], a @@ -579,7 +578,11 @@ class _DraggableSheetExtent { /// or a user drag. void updateSize(double newSize, BuildContext context) { assert(newSize != null); - _currentSize.value = clampDouble(newSize, minSize, maxSize); + final double clampedSize = clampDouble(newSize, minSize, maxSize); + if (_currentSize.value == clampedSize) { + return; + } + _currentSize.value = clampedSize; DraggableScrollableNotification( minExtent: minSize, maxExtent: maxSize, diff --git a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart index c18bd3aa8c..e93fb5c5a7 100644 --- a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart +++ b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart @@ -950,9 +950,7 @@ void main() { goTo(.5); await tester.pumpAndSettle(); goTo(0); - // The animation was cut short by half, there should have been on less pumps - final int truncatedPumpCount = shouldAnimate ? expectedPumpCount - 1 : expectedPumpCount; - expect(await tester.pumpAndSettle(), truncatedPumpCount); + expect(await tester.pumpAndSettle(), expectedPumpCount); expect( tester.getSize(find.byKey(containerKey)).height / screenHeight, closeTo(.25, precisionErrorTolerance), @@ -1007,6 +1005,29 @@ void main() { ); }); + testWidgets('Can animateTo with a Curves.easeInOutBack curve begin min-size', (WidgetTester tester) async { + const Key stackKey = ValueKey('stack'); + const Key containerKey = ValueKey('container'); + final DraggableScrollableController controller = DraggableScrollableController(); + await tester.pumpWidget(boilerplateWidget( + null, + initialChildSize: 0.25, + controller: controller, + stackKey: stackKey, + containerKey: containerKey, + )); + await tester.pumpAndSettle(); + final double screenHeight = tester.getSize(find.byKey(stackKey)).height; + + controller.animateTo(.6, curve: Curves.easeInOutBack, duration: const Duration(milliseconds: 500)); + + await tester.pumpAndSettle(); + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.6, precisionErrorTolerance), + ); + }); + testWidgets('Can reuse a controller after the old controller is disposed', (WidgetTester tester) async { const Key stackKey = ValueKey('stack'); const Key containerKey = ValueKey('container');