0

我正在尝试使自定义画家的三角形具有圆角。左边的图像是我到目前为止所拥有的,右边的图像是我想做的。

试过这个 想要达到这个

这是我的代码。

 class Triangle extends StatelessWidget {
  const Triangle({
    Key? key,
  }) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return CustomPaint(
        painter: MyPainter(),
        child: Container(
            height: MySize.yMargin(10),
            width: MySize.xMargin(20),
            decoration: BoxDecoration(borderRadius: BorderRadius.circular(30)),
            child: Center(
                child: Padding(
                    padding: const EdgeInsets.only(left: 30.0, bottom: 16),
                    child: Transform.rotate(
                        angle: math.pi / 4,
                        child: Text('New',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: MySize.textSize(5),
                              fontWeight: FontWeight.bold,
                            )))))));
  }
}

class MyPainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint();
    paint.color = Colors.yellow;
    var path = Path();
    path.lineTo(size.width, 0);
    path.lineTo(size.height, size.width);
    path.close();
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}
4

2 回答 2

0

尝试这个:

import 'package:vector_math/vector_math.dart' as vector;

        child: Container(
          color: Colors.yellow,
          width: 300,
          height: 100,
          child: Stack(
            children: [
              Positioned(
                top: -20,
                right: -20,
                child: Transform.rotate(
                  angle: vector.radians(45),
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(10)),
                    child: Container(
                      alignment: Alignment.bottomCenter,
                      height: 50,
                      width: 50,
                      color: Color(0xff2DD485),
                      child: Text('NEW'),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
于 2021-09-03T03:02:29.817 回答
0

你可以试试看这个

于 2021-09-02T21:24:51.327 回答