我正在尝试创建一个中心文本具有最大大小的行,如果文本内容太大,它适合大小。
我插入 TextOverflow.ellipsis
属性以缩短文本并插入三点 ...
但它不起作用。
main.dart
nhập 'gói:flutter/material.dart';
hàm main() {
runApp(MyApp mới());
}
lớp MyApp mở rộng StatelessWidget {
@ghi đè
Xây dựng tiện ích (BuildContext context) {
trả về MaterialApp mới(
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@ghi đè
Widget build(BuildContext context) => new Scaffold(
appBar: AppBar mới(
backgroundColor: new Color(0xFF26C6DA),
),
body: new ListView (
trẻ em: [
new Card(
child: new Container(
padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),
child: new Row(
trẻ em: [
Container mới(
padding: new EdgeInsets.only(right: 24.0),
child: new CircleAvatar(
backgroundColor: new Color(0xFFF5F5F5),
radius: 16.0,
)
),
Container mới(
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,
),
),
),
Container mới(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.end,
trẻ em: [
new Row(
trẻ em: [
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(
trẻ em: [
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)
),
),
],
),
]
)
)
],
),
)
),
]
)
);
}
kết quả:
预期:
您应该将您的 Container
包装在 Flexible
中让您的 Hàng ngang
Biết Container
比其固有宽度窄是可以的。 Expanded
也可以。
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,
),
),
),
),
Tôi là một lập trình viên xuất sắc, rất giỏi!