【发布时间】:2021-11-24 02:59:54
【问题描述】:
我正在尝试实现以下行为: 当文本长度超过 1 位时,文本周围会变成椭圆形。 当然,应该是动态的,比如在whatsapp上:
这是我尝试过的,但这不是您所看到的最佳实践(定位小部件是因为它在堆栈上):
if (num > 99) {
return Positioned(
right: 0,
top: 5,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Container(
width: 30,
height: 20,
decoration: new BoxDecoration(
color: orange,
),
child: Center(child:Text("99+",
style: TextStyle(
color: listBackground,
fontWeight: FontWeight.bold,
fontSize: 12,
fontFamily: 'Roboto-Regular',
)),
) )));
}
String value = num > 9? "9+" : num.toString();
return Positioned(
right: 0,
top: 5,
child: CircleAvatar(
radius: 10.0,
backgroundColor: orange,
child: Text(value,
style: TextStyle(
color: listBackground,
fontWeight: FontWeight.bold,
fontSize: 12,
fontFamily: 'Roboto-Regular',
))),
);
有更好的想法吗?
【问题讨论】:
-
检查
StadiumBorder并将其与ShapeDecoration一起使用
标签: flutter dart user-interface flutter-layout flutter-widget