如何在 Flutter 中根据具有动态大小的小部件的大小设置圆角半径

How to set corner radius based on size on a widget with dynamic size in Flutter

如何使用公式 radius = hight/2 确定小部件的角半径,该按钮在其子项后调整大小?

本例中的子项是一个文本,与传递的字符串一样长。

这就是我得到的。 我将 hight 和 maxWidth 设置为零以包裹文本大小,但我无法想出在应用角半径时测量宽度的方法。

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,
    ),
  ),
)