Skip to content

Commit

Permalink
Fix DDS do not support Curves.easeInOutBack curve (flutter#114222)
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-baolin committed Oct 28, 2022
1 parent cdbb1e6 commit 8469896
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
17 changes: 10 additions & 7 deletions packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 24 additions & 3 deletions packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1007,6 +1005,29 @@ void main() {
);
});

testWidgets('Can animateTo with a Curves.easeInOutBack curve begin min-size', (WidgetTester tester) async {
const Key stackKey = ValueKey<String>('stack');
const Key containerKey = ValueKey<String>('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<String>('stack');
const Key containerKey = ValueKey<String>('container');
Expand Down

0 comments on commit 8469896

Please sign in to comment.