[英]How to add rounded border to Rect class in flutter
我試圖為在 flutter 中使用 Painter 制作的矩形添加圓角邊框,
@override
void paint(Canvas canvas, Size size) {
Rect myRect = const Offset(0.0, 25.0) & const Size(200.0, 30.0);
canvas.drawRect(myRect, fillPainter);
}
我知道我可以使用 BoxDecoration 來繪制一個圓角矩形。 但我想為這個矩形添加更多形狀。
你可以這樣做:
@override
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {
Paint paint = Paint()
..color = Colors.red
..style = PaintingStyle.stroke
..strokeWidth = 2.0;
Path path = Path()
..addRRect(RRect.fromRectAndRadius(rect, Radius.circular(radius)));
canvas.drawPath(path, paint);
}
這是一篇很好的文章,解釋了如何制作其他形狀: Flutter 中的路徑:視覺指南
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.