Pinned.fromSize constructor

Pinned.fromSize({
  1. Key? key,
  2. required Rect bounds,
  3. required Size size,
  4. bool pinLeft = false,
  5. bool pinRight = false,
  6. bool pinTop = false,
  7. bool pinBottom = false,
  8. bool fixedWidth = false,
  9. bool fixedHeight = false,
  10. required Widget child,
})

Constructs a Pinned instance based on parameters that reflect the layout UI in Adobe XD:

  • size - the original dimensions of the parent
  • bounds - the original boundaries of the child within its parent
  • pin parameters that indicate the child should be pinned to an absolute position for that side
  • parameters indicating if it should use a fixed width or height

The first two values are used for calculating the initial position of the child within its parent. That initial position is then used in conjunction with the other parameters to construct the hPin and vPin objects used by Pinned.

Implementation

Pinned.fromSize({
  Key? key,
  required Rect bounds,
  required Size size,
  bool pinLeft = false,
  bool pinRight = false,
  bool pinTop = false,
  bool pinBottom = false,
  bool fixedWidth = false,
  bool fixedHeight = false,
  required Widget child,
}) : this.fromPins(
          Pin(
            size: fixedWidth ? bounds.width : null,
            start: pinLeft ? bounds.left : null,
            end: pinRight ? size.width - bounds.right : null,
            startFraction:
                !pinLeft && !fixedWidth ? bounds.left / size.width : null,
            endFraction: !pinRight && !fixedWidth
                ? (size.width - bounds.right) / size.width
                : null,
            middle: fixedWidth && !pinLeft && !pinRight
                ? bounds.left / (size.width - bounds.width)
                : null,
          ),
          Pin(
            size: fixedHeight ? bounds.height : null,
            start: pinTop ? bounds.top : null,
            end: pinBottom ? size.height - bounds.bottom : null,
            startFraction:
                !pinTop && !fixedHeight ? bounds.top / size.height : null,
            endFraction: !pinBottom && !fixedHeight
                ? (size.height - bounds.bottom) / size.height
                : null,
            middle: fixedHeight && !pinTop && !pinBottom
                ? bounds.top / (size.height - bounds.height)
                : null,
          ),
          child: child,
          key: key);