flutter 文字过长超出范围,Flutter-溢出时自动换行,例如插入省略号或淡入淡出...

I'm trying to create a line in which center text has a maximum size, and if the text content is too large, it fits in size.

I insert the TextOverflow.ellipsis property to shorten the text and inserting the triple points ... but it is not working.

main.dart

import 'package:flutter/material.dart';

void main() {

runApp(new MyApp());

}

class MyApp extends StatelessWidget {

@override

Widget build(BuildContext context) {

return new MaterialApp(

home: new HomePage(),

);

}

}

class HomePage extends StatelessWidget {

@override

Widget build(BuildContext context) => new Scaffold(

appBar: new AppBar(

backgroundColor: new Color(0xFF26C6DA),

),

body: new ListView (

children: [

new Card(

child: new Container(

padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),

child: new Row(

children: [

new Container(

padding: new EdgeInsets.only(right: 24.0),

child: new CircleAvatar(

backgroundColor: new Color(0xFFF5F5F5),

radius: 16.0,

)

),

new Container(

padding: new EdgeInsets.only(right: 13.0),

child: new Text(

'Text lar...',

overflow: TextOverflow.ellipsis,

style: new TextStyle(

fontSize: 13.0,

fontFamily: 'Roboto',

color: new Color(0xFF212121),

fontWeight: FontWeight.bold,

),

),

),

new Container(

child: new Column(

crossAxisAlignment: CrossAxisAlignment.end,

children: [

new Row(

children: [

new Text(

'Bill ',

style: new TextStyle(

fontSize: 12.0,

fontFamily: 'Roboto',

color: new Color(0xFF9E9E9E)

),

),

new Text(

'\$ -999.999.999,95',

style: new TextStyle(

fontSize: 14.0,

fontFamily: 'Roboto',

color: new Color(0xFF212121)

),

),

],

),

new Row(

children: [

new Text(

'Limit ',

style: new TextStyle(

fontSize: 12.0,

fontFamily: 'Roboto',

color: new Color(0xFF9E9E9E)

),

),

new Text(

'R\$ 900.000.000,95',

style: new TextStyle(

fontSize: 14.0,

fontFamily: 'Roboto',

color: new Color(0xFF9E9E9E)

),

),

],

),

]

)

)

],

),

)

),

]

)

);

}

result:

HKiLt.png

expected:

rGk9W.png

解决方案

You should wrap your Container in a Flexible to let your Row know that it's ok for the Container to be narrower than its intrinsic width. Expanded will also work.

o2nyO.png

Flexible(

child: new Container(

padding: new EdgeInsets.only(right: 13.0),

child: new Text(

'Text largeeeeeeeeeeeeeeeeeeeeeee',

overflow: TextOverflow.ellipsis,

style: new TextStyle(

fontSize: 13.0,

fontFamily: 'Roboto',

color: new Color(0xFF212121),

fontWeight: FontWeight.bold,

),

),

),

),

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值