gpt4 book ai didi

堆叠的列和行中的 Flutter Textwrapping

转载 作者:IT王子 更新时间:2023-10-29 07:00:28 27 4
gpt4 key购买 nike

我在将文本包装在堆叠的列和行中时遇到了一些麻烦(而且我不太确定我是否在做良好的练习;))。我尝试使用 Flexible 而不是 Wrapped,但它也没有用。

This is how it looks:

代码:

ListView(children: <Widget>[
Card(child: Padding(padding: EdgeInsets.all(16.0), child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
Text('Subhead', style: Theme.of(context).textTheme.subhead),
Padding(padding: EdgeInsets.only(bottom: 8.0)),
Row(crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
Text('Row title:', style: Theme.of(context).textTheme.caption),
Column(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
Text('24.04.2018', style: Theme.of(context).textTheme.caption),
Wrap(children: <Widget>[ Text('Very, very, very, very long text that needs to wrap', softWrap: true, style: Theme.of(context).textTheme.caption)],),
Text('Another line of text', style: Theme.of(context).textTheme.caption),
])
]),
Padding(padding: EdgeInsets.only(bottom: 8.0)),
Text('Next row title', style: Theme.of(context).textTheme.body1),
])))
]);

最佳答案

有很多方法可以解决您的问题,其中之一是使用 FlexFlexible,如下所示:

    return ListView(shrinkWrap: true, children: <Widget>[
Card(
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Subhead',
style: Theme.of(context).textTheme.subhead),
Padding(padding: EdgeInsets.only(bottom: 8.0)),
Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Flexible(
fit: FlexFit.tight,
flex: 1,
child: Text('Row title:',
style: Theme.of(context).textTheme.caption),
),
Flexible(
fit: FlexFit.tight,
flex: 4,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: <Widget>[
Text('24.04.2018',
style: Theme.of(context)
.textTheme
.caption),
Text(
'Very, very, very, very long text that needs to wrap',
softWrap: true,
style: Theme.of(context)
.textTheme
.caption),
Text('Another line of text',
style: Theme.of(context)
.textTheme
.caption),
]),
)
]),
Padding(padding: EdgeInsets.only(bottom: 8.0)),
Text('Next row title',
style: Theme.of(context).textTheme.body1),
])))
]);

关于堆叠的列和行中的 Flutter Textwrapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811033/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com