我想我已经理解了这些枚举是如何基于这个post工作的。当我使用以下代码尝试它时,它似乎不起作用。
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.ideographic,
children: <Widget>[
Text(
'abcdefg',
style: TextStyle(
fontSize: 50.0, fontWeight: FontWeight.w900),
),
Text(
'hi',
style: TextStyle(fontSize: 15.0),
),
],
),
但是,无论我选择将其用作文本基线(表意文字还是失语症),结果总是相同的:
我希望"hi“与"abcdefg”的表意基线对齐,而不是像这样与其字母基线对齐:
我做错了什么?
编辑:
在Row
小部件的上下文中,这两者应该有所不同。我尝试删除行textBaseline: TextBaseline.ideographic
,得到以下错误:
'package:flutter/src/widgets/basic.dart': Failed assertion: line 3791 pos 15: 'crossAxisAlignment != CrossAxisAlignment.baseline || textBaseline != null': is not true.
要求使用哪条基线必须是Flutter知道要对齐哪条基线的方式。
发布于 2020-06-07 17:39:46
截图:
你不需要基线。
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
'abcdefg',
style: TextStyle(fontSize: 50.0, fontWeight: FontWeight.w900),
),
Text(
'hi',
style: TextStyle(fontSize: 15.0),
),
],
)
发布于 2020-06-03 20:19:35
我不完全知道你的问题,但我认为你的问题可以通过添加以下参数来解决:
mainAxisSize: MainAxisSize.min,
所以我们有:
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
mainAxisSize: MainAxisSize.min,
textBaseline: TextBaseline.ideographic,
children: <Widget>[
Text(
'abcdefg',
style: TextStyle(
fontSize: 50.0, fontWeight: FontWeight.w900),
),
Text(
'hi',
style: TextStyle(fontSize: 15.0),
),
],
),
发布于 2020-06-14 14:49:43
所以,我做了一些挖掘,在这篇文章here上找到了一些信息。
根据这篇文章:
"alphabetic"
The text baseline is the normal alphabetic baseline. Default value.
"ideographic"
The text baseline is the ideographic baseline; this is the bottom of the body of the characters,
if the main body of characters protrudes beneath the alphabetic baseline.
(Used by Chinese, Japanese, and Korean scripts.)
根据这一点,输出应该是可微的,如问题中所述。因此,为了测试解释的第二部分,我尝试将其与汉字一起使用。
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.ideographic,
children: <Widget>[
Text(
'的',
style: TextStyle(
fontSize: 100.0),
),
Text(
'的',
style: TextStyle(fontSize: 15.0),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
Text(
'的',
style: TextStyle(
fontSize: 100.0),
),
Text(
'的',
style: TextStyle(fontSize: 15.0),
),
],
),
],
),
),
输出是this。
正如您所看到的,这也不是预期的输出,两者以相同的方式工作。因此,可以安全地假设在Flutter的这些枚举的实现中可能存在一些问题。
https://stackoverflow.com/questions/62171872
复制相似问题