Text 在flatter';文本基线枚举
颤振中的Text 在flatter';文本基线枚举,text,flutter,baseline,fontmetrics,Text,Flutter,Baseline,Fontmetrics,颤振中的TextBaselineenum有两个选项: 字母的 表意文字 这些值实际上是如何更改基线的?textbeliness.alphaloc 字母基线是像英语这样的字母表中的字母所在的线。以下是一个例子: 你可以看到英文字母排得很整齐,但它会划破汉字 表意文字 但是,当您使用表意文字选项时,基线位于文本区域的底部。请注意,汉字实际上并不在直线上。相反,该行位于文本行的最底部 补充守则 您可以将其插入CustomPaint小部件(如上所述)以重现上述示例 @override void
TextBaseline
enum有两个选项:
- 字母的
- 表意文字
CustomPaint
小部件(如上所述)以重现上述示例
@override
void paint(Canvas canvas, Size size) {
final textStyle = TextStyle(
color: Colors.black,
fontSize: 30,
);
final textSpan = TextSpan(
text: 'My text 文字',
style: textStyle,
);
final textPainter = TextPainter(
text: textSpan,
textDirection: TextDirection.ltr,
);
textPainter.layout(
minWidth: 0,
maxWidth: size.width,
);
print('width: ${textPainter.width}');
print('height: ${textPainter.height}');
// draw a rectangle around the text
final left = 0.0;
final top = 0.0;
final right = textPainter.width;
final bottom = textPainter.height;
final rect = Rect.fromLTRB(left, top, right, bottom);
final paint = Paint()
..color = Colors.red
..style = PaintingStyle.stroke
..strokeWidth = 1;
canvas.drawRect(rect, paint);
// draw the baseline
final distanceToBaseline =
textPainter.computeDistanceToActualBaseline(TextBaseline.ideographic);
print('distanceToBaseline: ${distanceToBaseline}');
canvas.drawLine(
Offset(0, distanceToBaseline),
Offset(textPainter.width, distanceToBaseline),
paint,
);
// draw the text
final offset = Offset(0, 0);
textPainter.paint(canvas, offset);
}
我正在我的行小部件中使用枚举。但是基线属性似乎不起作用。能在这里检查一下我的问题吗?