animateTo method Null safety

Future<void> animateTo(
  1. double size,
  2. {required Duration duration,
  3. required Curve curve}

Animates the attached sheet from its current size to size to the provided new size, a fractional value of the parent container's height.

Any active sheet animation is canceled. If the sheet's internal scrollable is currently animating (e.g. responding to a user fling), that animation is canceled as well.

An animation will be interrupted whenever the user attempts to scroll manually, whenever another activity is started, or when the sheet hits its max or min size (e.g. if you animate to 1 but the max size is .8, the animation will stop playing when it reaches .8).

The duration must not be zero. To jump to a particular value without an animation, use jumpTo.

When calling animateTo in widget tests, awaiting the returned Future may cause the test to hang and timeout. Instead, use WidgetTester.pumpAndSettle.


Future<void> animateTo(
  double size, {
  required Duration duration,
  required Curve curve,
}) async {
  assert(size >= 0 && size <= 1);
  assert(duration !=;
  final AnimationController animationController = AnimationController.unbounded(
    vsync: _attachedController!.position.context.vsync,
    value: _attachedController!.extent.currentSize,
  // This disables any snapping until the next user interaction with the sheet.
  _attachedController!.extent.hasDragged = false;
  _attachedController!.extent.startActivity(onCanceled: () {
    // Don't stop the controller if it's already finished and may have been disposed.
    if (animationController.isAnimating) {
  animationController.addListener(() {
    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);