diff --git a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart index b515af55f2..d24e72271c 100644 --- a/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart +++ b/packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart @@ -117,7 +117,7 @@ class DraggableScrollableController extends ChangeNotifier { animationController.stop(); } }); - CurvedAnimation(parent: animationController, curve: curve).addListener(() { + animationController.addListener(() { _attachedController!.extent.updateSize( animationController.value, _attachedController!.position.context.notificationContext!, @@ -128,7 +128,7 @@ class DraggableScrollableController extends ChangeNotifier { animationController.stop(canceled: false); } }); - await animationController.animateTo(size, duration: duration); + await animationController.animateTo(size, duration: duration, curve: curve); } /// Jumps the attached sheet from its current size to the given [size], a diff --git a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart index 20d304cadf..489d7cbaed 100644 --- a/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart +++ b/packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart @@ -785,6 +785,53 @@ void main() { }); } + testWidgets('Can animateTo with a nonlinear curve', (WidgetTester tester) async { + const Key stackKey = ValueKey('stack'); + const Key containerKey = ValueKey('container'); + final DraggableScrollableController controller = DraggableScrollableController(); + await tester.pumpWidget(_boilerplate( + null, + controller: controller, + stackKey: stackKey, + containerKey: containerKey, + )); + await tester.pumpAndSettle(); + final double screenHeight = tester.getSize(find.byKey(stackKey)).height; + + controller.animateTo(.6, curve: Curves.linear, duration: const Duration(milliseconds: 100)); + // We need to call one pump first to get the animation to start. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 50)); + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.55, precisionErrorTolerance), + ); + await tester.pumpAndSettle(); + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.6, precisionErrorTolerance), + ); + + controller.animateTo(.7, curve: const Interval(.5, 1), duration: const Duration(milliseconds: 100)); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 50)); + // The curve should result in the sheet not moving for the first 50 ms. + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.6, precisionErrorTolerance), + ); + await tester.pump(const Duration(milliseconds: 25)); + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.65, precisionErrorTolerance), + ); + await tester.pumpAndSettle(); + expect( + tester.getSize(find.byKey(containerKey)).height / screenHeight, + closeTo(.7, 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');