【发布时间】:2019-08-17 18:33:27
【问题描述】:
我想用文字绘制一个三角形,在卡片的右上角绝对位置
例如:
我几乎做到了,但是 1.我想知道有没有简单的方法 2.文字不完全居中...
这是我的代码:(我对三角形使用绘画并为文本使用旋转)
class ShapesPainter extends CustomPainter {
final Color color;
ShapesPainter(this.color);
@override
void paint(Canvas canvas, Size size) {
final paint = Paint();
paint.color = color;
// create a path
var path = Path();
path.moveTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(size.width - size.height, 0);
// close the path to form a bounded shape
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
class EventStatusIndicator extends StatelessWidget{
final E.EventStatus eventStatus;
EventStatusIndicator(this.eventStatus);
Widget build(ct) {
return Stack(
children: <Widget>[
CustomPaint(
painter: ShapesPainter(eventStatusMap[this.eventStatus].color),
child: Container(
height: 100,
),
),
Align (alignment: Alignment.topRight, child: Container(
margin: EdgeInsets.fromLTRB(0, 30, 0, 0),
height: 60.0,
width: 90,
child: Transform.rotate(angle: math.pi / 4, child:
Text(eventStatusMap[this.eventStatus].display, textAlign: TextAlign.center, style: TextStyle(color: eventStatusIndicatorColor, fontSize: 17)))
))
],
);
}
}
【问题讨论】:
标签: flutter