Flutter 使文本在一行中可单击,并处理溢出
我希望变量Flutter 使文本在一行中可单击,并处理溢出,flutter,flutter-layout,Flutter,Flutter Layout,我希望变量location标识的字符串可以单击,如果溢出,请使用省略号隐藏溢出的字符。但是,如果location足够短,不需要省略号,我不希望行中剩余的空间可以单击 Row( children: <Widget>[ Text('Location: '), Expanded( child: InkWell( onTap: () { // do something },
location
标识的字符串可以单击,如果溢出,请使用省略号隐藏溢出的字符。但是,如果location
足够短,不需要省略号,我不希望行中剩余的空间可以单击
Row(
children: <Widget>[
Text('Location: '),
Expanded(
child: InkWell(
onTap: () { // do something },
child: Text(
'$location',
overflow: TextOverflow.ellipsis,
), // Text
), // InkWell
), // Expanded
], // <Widget>[]
),
要使$location仅可单击,只需将“Expanded”替换为“Flexible”,因为Flexible会将小部件的大小缩小到其内容,而不是像Expanded那样缩小到其父级的大小,例如:
子项:行(
儿童:[
文本('位置:'),
//将“扩展”替换为“灵活”
灵活的(
孩子:InkWell(
onTap:(){},
子:文本(
“$location”,
溢出:TextOverflow.省略号,
),//文本
),//InkWell
),//灵活
], // []
),
RichText(
text: TextSpan(
children: [
TextSpan(text: 'Location: '),
TextSpan(
text: '$location',
recognizer: TapGestureRecognizer()
..onTap = () {
// do something
},
),
],
),
),