【发布时间】:2023-03-23 23:10:01
【问题描述】:
如何使用公式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'),
),
);
我已经在网上搜索过,但没有任何结果。
【问题讨论】:
-
我已将其从按钮中移出,以便在同一个小部件中收集所有变量。这两种方式都没有区别。
-
参见
StadiumBorder实现 -
谢谢。它做我需要的,但不是我想要的。真的希望我能以某种方式得到孩子的大小。
-
用 LayoutBuilder 包裹 RaisedButton,你将拥有
constraints参数和大小 -
我这样做了,但约束 maxWidth 和 maxHeight 显示了我认为是其父容器的内容。在这种情况下,它所在的卡。
标签: flutter flutter-layout cornerradius