performAlignment method

void performAlignment(
  1. AppBarAlignmentCommand command
)

Animates alignment of the appbar by a given scroll position and a given appbar alignment behavior.

Implementation

void performAlignment(AppBarAlignmentCommand command) {
  final start = pixels;
  final end =
      command == AppBarAlignmentCommand.shrink ? maxExtent : minExtent;

  /// If the target pixels and the current pixels are the same,
  /// a appbar is no need to align.
  if ((pixels - end).abs() < precisionErrorTolerance) {
    return;
  }

  _animation?.dispose();
  _animation =
      AnimationController(vsync: vsync, duration: behavior.alignDuration);
  _animation!.addListener(() {
    final newVector = end - start;
    final newPixels = start +
        (newVector * behavior.alignCurve.transform(_animation!.value));

    setPixels(newPixels);
  });
  _animation!.forward();
}