본문 바로가기
Flutter

ShapeBorder -> pentagon

by Andro07 2024. 1. 7.
728x90
반응형

 

class _pentagonBorder extends ShapeBorder {
  @override
  EdgeInsetsGeometry get dimensions => EdgeInsets.only();

  @override
  Path getInnerPath(Rect rect, {TextDirection? textDirection}) {
    return getOuterPath(rect, textDirection: textDirection!);
  }

  @override
  Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
    return Path()
      ..moveTo(rect.left + rect.width / 2.0, rect.top)
      ..lineTo(rect.right, rect.top + rect.height / 2.0)
      ..lineTo(rect.right - 20.0, rect.top + rect.height)
      ..lineTo(rect.left + rect.width, rect.bottom)
      ..lineTo(rect.left + 20.0, rect.top + rect.height)
      ..lineTo(rect.left + rect.width - 100.0, rect.bottom - rect.height / 2.0)
      ..close();
  }

  @override
  void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}

  @override
  ShapeBorder scale(double t) {
    return RoundedRectangleBorder(
      side: BorderSide.none.scale(t),
      borderRadius: BorderRadius.zero * t,
    );
  }
}

 

RawMaterialButton(
  onPressed: () => {},
  constraints: BoxConstraints.tightFor(
      width: 100.0, // double? width
      height: 100.0 // double? height
      ),
  fillColor: Colors.amber,
        shape: _pentagonBorder(),
)

 

728x90
728x90

댓글