relative static method

Widget relative(
  1. Widget main,
  2. Widget relative, {
  3. Key? key,
  4. Widget? child,
  5. Alignment? alignment,
  6. double? dx,
  7. double? dy,
  8. double? moveByChildWidth,
  9. double? moveByChildHeight,
  10. double? moveByContainerWidth,
  11. double? moveByContainerHeight,
  12. double? moveVerticallyByChildWidth,
  13. double? moveHorizontallyByChildHeight,
  14. double? moveVerticallyByContainerWidth,
  15. double? moveHorizontallyByContainerHeight,
  16. double? childWidth,
  17. double? childHeight,
  18. double? minChildWidth,
  19. double? minChildHeight,
  20. double? maxChildWidth,
  21. double? maxChildHeight,
  22. double? childWidthRatio,
  23. double? childHeightRatio,
  24. double? minChildWidthRatio,
  25. double? minChildHeightRatio,
  26. double? maxChildWidthRatio,
  27. double? maxChildHeightRatio,
  28. double? rotateDegrees,
  29. Matrix4Transform? matrix4Transform,
  30. Wins wins = Wins.min,
  31. Touch touch = Touch.inside,
})

Use this if you have a main widget, and you want to position/size/rotate/translate another widget relative to the main one, but the second is NOT a child of the first.

Example, to center the main widget, and then put the relative widget below it:

Center(
   child: AlignPositioned.relative(
       widgetA(),
       widgetB(),
       moveByContainerHeight: 0.5,
       moveByChildHeight: 0.5));

Implementation

static Widget relative(
  Widget main,
  Widget relative, {
  Key? key,
  Widget? child,
  Alignment? alignment,
  double? dx,
  double? dy,
  double? moveByChildWidth,
  double? moveByChildHeight,
  double? moveByContainerWidth,
  double? moveByContainerHeight,
  double? moveVerticallyByChildWidth,
  double? moveHorizontallyByChildHeight,
  double? moveVerticallyByContainerWidth,
  double? moveHorizontallyByContainerHeight,
  double? childWidth,
  double? childHeight,
  double? minChildWidth,
  double? minChildHeight,
  double? maxChildWidth,
  double? maxChildHeight,
  double? childWidthRatio,
  double? childHeightRatio,
  double? minChildWidthRatio,
  double? minChildHeightRatio,
  double? maxChildWidthRatio,
  double? maxChildHeightRatio,
  double? rotateDegrees,
  Matrix4Transform? matrix4Transform,
  Wins wins = Wins.min,
  Touch touch = Touch.inside,
}) {
  return Stack(children: [
    main,
    AlignPositioned.expand(
      child: relative,
      alignment: alignment,
      dx: dx,
      dy: dy,
      moveByChildWidth: moveByChildWidth,
      moveByChildHeight: moveByChildHeight,
      moveByContainerWidth: moveByContainerWidth,
      moveByContainerHeight: moveByContainerHeight,
      moveVerticallyByChildWidth: moveVerticallyByChildWidth,
      moveHorizontallyByChildHeight: moveHorizontallyByChildHeight,
      moveVerticallyByContainerWidth: moveVerticallyByContainerWidth,
      moveHorizontallyByContainerHeight: moveHorizontallyByContainerHeight,
      childWidth: childWidth,
      childHeight: childHeight,
      minChildWidth: minChildWidth,
      minChildHeight: minChildHeight,
      maxChildWidth: maxChildWidth,
      maxChildHeight: maxChildHeight,
      childWidthRatio: childWidthRatio,
      childHeightRatio: childHeightRatio,
      minChildWidthRatio: minChildWidthRatio,
      minChildHeightRatio: minChildHeightRatio,
      maxChildWidthRatio: maxChildWidthRatio,
      maxChildHeightRatio: maxChildHeightRatio,
      rotateDegrees: rotateDegrees,
      matrix4Transform: matrix4Transform,
      wins: wins,
      touch: touch,
    ),
  ]);
}