如何在 GridView 页脚中包装文本(根据需要换行以显示全部内容)
How to wrap a text (break its lines as needed to show the whole content) in a GridView's footer
我有一个用这段代码制作的网格图块:
child: GridTile(
child: Hero(
tag: "${item}",
child: setIcon(item)
footer: Container(
padding: EdgeInsets.all(8.0),
height: 50,
color: Colors.white70,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
],
),
),
),
),
它给了我这个结果:
如何调整我的文本以显示整个文本(不带“...”)?如您所见,它只显示了一些字符,我想显示所有单词。我该怎么做?
更新
使用此代码,它仍然等于照片
footer: Container(
padding: EdgeInsets.all(8.0),
color: Colors.white70,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
)
],
),
),
并使用此代码抛出第 1785 行 pos 12:'hasSize'
footer: Container(
padding: EdgeInsets.all(8.0),
color: Colors.white70,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
)
],
),
),
看看这个例子
// Add this widget as a parent to the text widget.
Expanded(
child: Text(
'asdfbnasdfmlqkw asknfwa wfn iwqf wfnwf qwoif qwoif qwef wfoiqwefnwefwq ',
style: TextStyle(
color: Theme.of(context).textTheme.caption.color,
),
),
),
删除
overflow: TextOverflow.ellipsis,
来自文本小部件参数
只需将展开的小部件作为父级添加到文本小部件,如下所示
强烈推荐AutoSizeText,很喜欢这个套餐
AutoSizeText(
text,
//dont set it, will resize the text to fit up to two lines
// overflow: TextOverflow.visible,
//set how many lines your text can have
maxLines: 2,
//set hoow big text can be
maxFontSize: 30,
//set how small the text can be..
minFontSize: 14,
),
我有一个用这段代码制作的网格图块:
child: GridTile(
child: Hero(
tag: "${item}",
child: setIcon(item)
footer: Container(
padding: EdgeInsets.all(8.0),
height: 50,
color: Colors.white70,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
],
),
),
),
),
它给了我这个结果:
如何调整我的文本以显示整个文本(不带“...”)?如您所见,它只显示了一些字符,我想显示所有单词。我该怎么做?
更新 使用此代码,它仍然等于照片
footer: Container(
padding: EdgeInsets.all(8.0),
color: Colors.white70,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
)
],
),
),
并使用此代码抛出第 1785 行 pos 12:'hasSize'
footer: Container(
padding: EdgeInsets.all(8.0),
color: Colors.white70,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item.elemento == null
? item.video['nome']
: item.elemento.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Theme
.of(context)
.textTheme
.caption
.color,
),
),
)
],
),
),
看看这个例子
// Add this widget as a parent to the text widget.
Expanded(
child: Text(
'asdfbnasdfmlqkw asknfwa wfn iwqf wfnwf qwoif qwoif qwef wfoiqwefnwefwq ',
style: TextStyle(
color: Theme.of(context).textTheme.caption.color,
),
),
),
删除
overflow: TextOverflow.ellipsis,
来自文本小部件参数
只需将展开的小部件作为父级添加到文本小部件,如下所示
强烈推荐AutoSizeText,很喜欢这个套餐
AutoSizeText(
text,
//dont set it, will resize the text to fit up to two lines
// overflow: TextOverflow.visible,
//set how many lines your text can have
maxLines: 2,
//set hoow big text can be
maxFontSize: 30,
//set how small the text can be..
minFontSize: 14,
),