【发布时间】:2019-06-05 05:32:13
【问题描述】:
我在一行中有一个文本小部件,我正在从 API 中检索谁的文本,并且有时会变得很长。我希望文本在太长时换行并移至下一行,但是它会溢出。 有没有办法来解决这个问题 ? 谢谢
我的代码
return ListView.builder(
itemCount: values == null ? 0 : values.length,
itemBuilder: (BuildContext context, int index) {
return Ink(
child: InkWell(
child: Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
.......
Row(children: <Widget>[Icon(Icons.account_balance, size: 13.0, color: Colors.grey),
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text(values[index].societyName, style: TextStyle(color: Colors.grey, fontSize: 15.0), maxLines: 2, overflow: TextOverflow.clip,), //TEXT HERE
)],),
.....
],
),
),
),
),
);
},
);
编辑:
我尝试使用 Expanded (和 Flexible )来包装我的行,但是它给出了以下错误:
I/flutter (16255): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (16255): The following assertion was thrown during performLayout():
I/flutter (16255): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (16255): When a column is in a parent that does not provide a finite height constraint, for example if it is
I/flutter (16255): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (16255): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (16255): space in the vertical direction.
I/flutter (16255): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (16255): cannot simultaneously expand to fit its parent.
I/flutter (16255): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (16255): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (16255): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (16255): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (16255): constraints provided by the parent.
这是因为我的列位于 ListView Card 中。 有没有其他方法可以解决这个问题?
我尝试了控制台中给出的建议,但没有奏效。
【问题讨论】:
标签: flutter