我有这样一种情况,即一行中有两个文本项。第一个文本可以有一个可变的长度,但我不想将文本分成两行。因此,我需要第一个文本被裁剪时,父级没有足够的宽度,它和第二个文本。现在,如果我不将文本排成一行,它就会按预期工作。但如果它们在行中,则不会发生剪切。我不能在展开的小部件中包装第一个文本(它修复了剪切问题),因为它在两个文本之间添加了一个空格。下面是一个代码片段
Container(
child: Row (
children: <Widget>[
Text("Long text that needs to be clipped",
overflow: TextOverflow.clip,
textAlign: TextAlign.left),
//there should be no blank space between the elements
Text( "+1",
textAlign: TextAlign.left,
overflow: TextOverflow.fade),
],
)
)

我已经挠头好一阵子了。
发布于 2019-07-08 18:28:11
我们可以按照下面的方法使用Expanded:
Material(
child: Container(
color: appColor,
child: Row(
children: <Widget>[
Expanded(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
"Lorem Ipsum is simply dummy text of the printing and typesetting industry.",
softWrap: false,
overflow: TextOverflow.fade,
style: TextStyle(color: Colors.white),
),
),
),
),
IconButton(
icon: Image.asset('assets/images/filter.png'),
onPressed: () {},
),
IconButton(
icon: Image.asset('assets/images/notification.png'),
onPressed: () {},
),
],
)),
);https://stackoverflow.com/questions/56925765
复制相似问题