biBeveledShape function

BeveledRectangleBorder biBeveledShape (
  1. {bool flip = false,
  2. double radius = 5,
  3. bool shrinkOneCorner = false,
  4. double ratio = 5 / 4,
  5. AlignmentGeometry shrinkCornerAlignment}
)

🔰 biBeveledShape

Returns a BeveledRectangleBorder where the passed radius is applied to two diagonally opposite corners while the other two remain square.

Default is beveled topRight and bottomLeft, but flip passed true will mirror the result.

Pass true to shrinkOneCorner to increase the radius on one of the resultant beveled corners based on Alignment pass to shrinkCornerAlignment.

This aids when stacking multiple biBeveledShape within one another when offset with padding while a uniform border is desired.

(See: [Surface._buildBiBeveledShape)

Implementation

BeveledRectangleBorder biBeveledShape({
  bool flip = false,
  double radius = 5,
  bool shrinkOneCorner = false,
  double ratio = 5 / 4,
  AlignmentGeometry shrinkCornerAlignment,
}) {
  flip ??= false;
  shrinkOneCorner ??= false;

  double tr = (flip) ? 0.0 : radius;
  double bl = (flip) ? 0.0 : radius;
  double tl = (flip) ? radius : 0.0;
  double br = (flip) ? radius : 0.0;

  if (shrinkOneCorner) {
    if ((shrinkCornerAlignment ?? Alignment.center) != Alignment.center) {
      if (shrinkCornerAlignment == Alignment.topRight)
        tr *= ratio;
      else if (shrinkCornerAlignment == Alignment.bottomRight)
        br *= ratio;
      else if (shrinkCornerAlignment == Alignment.bottomLeft)
        bl *= ratio;
      else if (shrinkCornerAlignment == Alignment.topLeft) tl *= ratio;
    }
  }

  // print('FLIP: $flip, shrinking? $shrinkOneCorner  |  tr: $tr, br: $br, bl: $bl, tl: $tl');

  return BeveledRectangleBorder(
      borderRadius: BorderRadius.only(
    topRight: Radius.circular(tr),
    bottomRight: Radius.circular(br),
    bottomLeft: Radius.circular(bl),
    topLeft: Radius.circular(tl),
  ));
}