getRelativeOffset method

Offset getRelativeOffset({
  1. required SizedConstraints sizedConstraints,
  2. required int index,
  3. required double ratio,
})

index's offset would be relative to the previous index's offset currently, each action item is laid out using a tight BoxConstraints so SizedConstraints.getShiftFromConstraints is used to get the size of the previous action item for ActionMotion.stretch and ActionMotion.drawer, the previous action item's size is multiplied by ratio, which is changed by the SlideController.animationValue for ActionMotion.behind, action items' origin do not change during animation, for ActionMotion.scroll, action items' origin are translated during animation

! different ActionPosition would translate differently based on its ActionMotion e.g. the translation is same for ActionPosition.pre/ActionMotion.scroll and ActionPosition.post/ActionMotion.behind

todo: to position action items based on its ActionMotion and ActionPosition when expanding

Implementation

Offset getRelativeOffset({
  required SizedConstraints sizedConstraints,
  required int index,
  required double ratio,
}) {
  assert(ratio >= 0 && ratio <= 1);
  final shift = _previousShift;

  switch (motion) {
    case ActionMotion.stretch || ActionMotion.drawer:
      _previousShift +=
          sizedConstraints.getShiftFromConstraints(index) * ratio;
      break;
    case ActionMotion.behind || ActionMotion.scroll:
      _previousShift += sizedConstraints.getShiftFromConstraints(index);
      break;
  }

  final shouldChangeOrigin =
      (motion == ActionMotion.scroll && position == ActionPosition.pre) ||
          (motion == ActionMotion.behind && position == ActionPosition.post);

  return shift +
      (shouldChangeOrigin
          ? sizedConstraints.totalShift * (ratio - 1)
          : Offset.zero);
}