flutter⽂字过长超出范围_flutter如何防⽌⽂本的溢出
⾥经常有⼩伙伴问,如何让text不溢出啊?这个问题并不难啊,似乎⼩伙伴们不知道如何去控制。
今天就以row组件为例,⽐如row组件⾥放了⼀个text和⼀个icon,现在这个row是占了⼿机的⼀⾏,如果text⽂本过长,很明显会造成溢出异常的
第⼀个技巧
overflow: TextOverflow.ellipsis
第⼆个技巧
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width - 50),
⼀般要搭配使⽤
Widget renderAddress() {
if (address != null) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width - 50),
child: new Text(
address.areaName + address.housePlate,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 20),
),
),
Icon(
Icons.chevron_right,
color: Colors.white70,
)
],
)
,textstyle
Container(
height: 4,
),
Text(
"${address.customerName} ${address.phone}",
style: TextStyle(
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w500,
letterSpacing: 1),
)
,
]);
}
return Row(
children: [
new Text(
"选择",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.w500, fontSize: 21), ),
Icon(
Icons.chevron_right,
color: Colors.white70,
)
],
);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论