createAnimation method

Animation<Offset> createAnimation(
  1. AnimationController controller,
  2. AntdAnimatedContext<WidgetType, StateType> context
)

Implementation

Animation<Offset> createAnimation(AnimationController controller,
    AntdAnimatedContext<WidgetType, StateType> context) {
  var widget = context.widget;
  var state = context.state;
  var mediaQueryData = MediaQuery.of(context.context);

  final screenWidth = mediaQueryData.size.width;
  final screenHeight = mediaQueryData.size.height;

  Offset beginOffset;
  Offset endOffset = Offset.zero;

  switch (widget.position) {
    case AntdPosition.top:
      beginOffset = const Offset(0, -1.0);
    case AntdPosition.bottom:
      beginOffset = const Offset(0, 1);
    case AntdPosition.left:
      beginOffset = const Offset(-1.0, 0);
    case AntdPosition.right:
      beginOffset = const Offset(1.0, 0);
    default:
      beginOffset = const Offset(0, 1.0);
  }

  switch (widget.position) {
    case AntdPosition.top:
      endOffset = Offset.zero;
    case AntdPosition.bottom:
      endOffset = Offset(0, 1 - state.popupHeight / screenHeight);
    case AntdPosition.left:
      endOffset = Offset.zero;
    case AntdPosition.right:
      endOffset = Offset(1 - state.popupWidth / screenWidth, 0);
    default:
      endOffset = const Offset(0, 1.0);
  }

  return Tween<Offset>(
    begin: beginOffset,
    end: endOffset,
  ).animate(
    CurvedAnimation(
      parent: controller,
      curve: const Interval(0.4, 1, curve: Curves.easeOutCubic),
    ),
  );
}