如何在按钮上使用公式 radius = hight/2
确定小部件的角半径,该按钮在其子项之后调整大小?
本例中的子项是一个文本,其长度可以与传递的字符串一样长。
这就是我得到的。 我将高度和最大宽度设置为零以包裹文本大小,但我无法找到在应用角半径时测量宽度的方法。
ButtonTheme(
height: 0,
minWidth: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(width/2)), //how can i calculate width?
child: RaisedButton(
onPressed: onPress,
child: Text('Some String of variable length'),
),
);
我在网上搜索过,但没有任何结果。
最佳答案
正如 @pskink 提到的,您可以使用 StadiumBorder :
A border that fits a stadium-shaped border (a box with semicircles on the ends) within the rectangle of the widget it is applied to.
下面是一个示例,在 TextField
上写入多行即可查看结果:
Center(
child: Container(
decoration: ShapeDecoration(
shape: StadiumBorder(
side: BorderSide(width: 2.0),
),
),
child: TextField(
textAlign: TextAlign.center,
minLines: 1,
maxLines: 100,
),
),
)
关于flutter - 如何根据 Flutter 中具有动态大小的小部件的大小设置角半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58412318/